diff requires input that is at least one dimensional
Package:
numpy
18118

Exception Class:
ValueError
Raise code
if n < 0:
raise ValueError(
"order must be non-negative but got " + repr(n))
a = asanyarray(a)
nd = a.ndim
if nd == 0:
raise ValueError("diff requires input that is at least one dimensional")
axis = normalize_axis_index(axis, nd)
combined = []
if prepend is not np._NoValue:
prepend = np.asanyarray(prepend)
if prepend.ndim == 0:
shape = list(a.shape)
Links to the raise (1)
https://github.com/numpy/numpy/blob/5f3c3181b5d8db0e430e5f605cc45c4392f04934/numpy/lib/function_base.py#L1258Ways to fix
Error Code:
import numpy as np
arr = 1
diff1 = np.diff(arr) <- ValueError: diff requires input that is at least one dimensional.
print(diff1)
Fix code:
import numpy as np
arr = [1] <- Here you've to change it, array should be at least one dimension. So you have to insert a list or at least one-dimensional array.
diff1 = np.diff(arr)
print(diff1)
Explanation:
np.diff contain a part of code-
nd = a.ndim
if nd == 0:
raise ValueError("diff requires input that is at least one dimensional")
If you input a number rather than a list or ndarray(where n = N) then, the value of nd would be 0 in code, which will raise an error.
Add a possible fix
Please authorize to post fix