Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert np.ndarray to np.array in python

Tags:

python

numpy

I have some data loaded as a np.ndarray and need to convert it to a np.array.

Is there an easy/quick way of doing this without having to re-load the data in a different way?

All the information I can find in tutorials seems to refer to one type of array or the other, but not how to change data from one to the other.

like image 313
user1499565 Avatar asked Jul 04 '12 20:07

user1499565


1 Answers

They are the same: numpy.array is a function that constructs an object of type numpy.ndarray.

>>> import numpy
>>> numpy.ndarray
<type 'numpy.ndarray'>
>>> numpy.array
<built-in function array>
>>> numpy.array([])
array([], dtype=float64)
>>> isinstance(numpy.array([]), numpy.ndarray)
True
like image 57
krlmlr Avatar answered Sep 20 '22 12:09

krlmlr