I cannot convert it to ndarray to numpy, I read http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html , but it doesnβt show me how I can convert my input, as shown below in ndarray .
How to build ndarray from numpy array or list of whole lists? * What is the difference between ndarray and array? * Could I just use the array type correctly?
I have a list of integers like this
[[1, 2, 4, 1, 5], [6, 0, 0, 0, 2], [0, 0, 0, 1, 0]]
And I manage to use this code to create np.array , as shown in http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html#numpy.array
import numpy as np x = [[1, 2, 4, 1, 5], [6, 0, 0, 0, 2], [0, 0, 0, 1, 0]] print np.array(x)
[output]:
[[1 2 4 1 5] [6 0 0 0 2] [0 0 0 1 0]]
But I can not change it to np.ndarray with this code:
import numpy as np x = [[1, 2, 4, 1, 5], [6, 0, 0, 0, 2], [0, 0, 0, 1, 0]] print np.ndarray(x)
There was an error:
Traceback (most recent call last): File "/home/alvas/workspace/sklearntut/test.py", line 7, in <module> print np.ndarray(x) TypeError: an integer is required
How to create np.ndarray with a list of integers that I have? What integer is talking about TypeError?