Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data type not understood while creating a NumPy array

Tags:

arrays

numpy

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?

like image 297
Victor Avatar asked Jan 12 '18 18:01

Victor


People also ask

What is the data type of a NumPy array?

NumPy numerical types are instances of dtype (data-type) objects, each having unique characteristics. The dtypes are available as np. bool_, np. float32, etc.

Can NumPy array hold different data types?

While a Python list can contain different data types within a single list, all of the elements in a NumPy array should be homogeneous.

How do I change Dtype to NP?

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.

What is Dtype U11 NumPy?

# 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.


1 Answers

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.

like image 168
Grr Avatar answered Sep 24 '22 09:09

Grr