Reputation: 17097
I am trying to create a 2 * 3 numpy array as below:
x_sample= np.array([31000,28.69,7055.47],[79000,3.9,16933.26]);
But I get:
TypeError: data type not understood
Why am I getting the error?
Upvotes: 5
Views: 19711
Reputation: 14255
The TypeError: data type not understood
also occurs when trying to create a structured array, if the names defined in the dtype
argument are not of type str
.
Consider this minimal example:
numpy.array([], dtype=[(name, int)])
type(name) is unicode
type(name) is bytes
type(name) is str
(tested with Python 2.7 + numpy 1.14, and Python 3.6 + numpy 1.15)
Upvotes: 0
Reputation: 323266
You can try
np.vstack(([31000,28.69,7055.47],[79000,3.9,16933.26]))
Upvotes: 0
Reputation: 16079
You are missing brackets around the two lists.
x_sample= np.array([[31000,28.69,7055.47],[79000,3.9,16933.26]])
The way it was written the dtype
argument was receiving the value [79000,3.9,16933.26]
, which obviously cannot be interpreted as a valid NumPy data type and caused the error.
Upvotes: 9