5

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?

0

3 Answers 3

9

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You can try

np.vstack(([31000,28.69,7055.47],[79000,3.9,16933.26]))

Comments

0

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)])
  • fails in Python 2 if type(name) is unicode
  • fails in Python 3 if type(name) is bytes
  • succeeds in Python 2 and 3 if type(name) is str

(tested with Python 2.7 + numpy 1.14, and Python 3.6 + numpy 1.15)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.