x must be a one-dimensional array
Package:
tensorflow
158813

Exception Class:
ValueError
Raise code
control_flow_ops.Assert(N >= 0, [N])
rank = array_ops.rank(x)
rank_temp = np_utils.get_static_value(rank)
if rank_temp is not None:
rank = rank_temp
if rank != 1:
raise ValueError('x must be a one-dimensional array')
else:
control_flow_ops.Assert(math_ops.equal(rank, 1), [rank])
if increasing:
start = 0
limit = N
delta = 1
🙏 Scream for help to Ukraine
Today, 25th May 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/tensorflow/tensorflow/blob/863af33dd172043502fcb9e4f63e09449a9b29f3/tensorflow/python/ops/numpy_ops/np_array_ops.py#L1324See also in the other packages (1)
(❌️ No answer)
jax/x-must-be-a-one-dimensional-array/
Ways to fix
tf.experimental.numpy.vander
generate a Vandermonde matrix the same way as numpy.vander
.
Usage:
result = tf.experimental.numpy.vander(x,
N=None,
increasing=False )
x is the input array and N is the number of columns in the output. x should be a 1D array.
Reproducing the error:
from tensorflow.experimental.numpy import vander
import numpy as np
x = np.array([[1, 2, 3, 5]])
N = 3
result = vander(x,N)
print(result)
The error output:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-b623fd1eef2a> in <module>
3 x = np.array([[1, 2, 3, 5]])
4 N = 3
----> 5 result = vander(x,N)
~/my_env_project/lib/python3.8/site-packages/tensorflow/python/ops/numpy_ops/np_array_ops.py in vander(x, N, increasing)
1316 rank = rank_temp
1317 if rank != 1:
-> 1318 raise ValueError('x must be a one-dimensional array')
1319 else:
1320 control_flow_ops.Assert(math_ops.equal(rank, 1), [rank])
ValueError: x must be a one-dimensional array
Fix:
Make sure the x is 1D array.
from tensorflow.experimental.numpy import vander
import numpy as np
x = np.array([1, 2, 3, 5])
N = 3
result = vander(x,N)
print(result)
Output:
tf.Tensor( [[ 1 1 1] [ 4 2 1] [ 9 3 1] [25 5 1]], shape=(4, 3), dtype=int64)
Add a possible fix
Please authorize to post fix