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?
NumPy numerical types are instances of dtype (data-type) objects, each having unique characteristics. The dtypes are available as np. bool_, np. float32, etc.
While a Python list can contain different data types within a single list, all of the elements in a NumPy array should be homogeneous.
In order to change the dtype of the given array object, we will use numpy. astype() function. The function takes an argument which is the target data type. The function supports all the generic types and built-in types of data.
# dtype('<U11') In the first case, each element of the list we pass to the array constructor is an integer. Therefore, NumPy decides that the dtype should be integer (32 bit integer to be precise). In the second case, one of the elements (3.0) is a floating-point number.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With