简体   繁体   English

在python中将np.ndarray转换为np.array

[英]Convert np.ndarray to np.array in python

I have some data loaded as a np.ndarray and need to convert it to a np.array. 我有一些数据作为np.ndarray加载,需要将其转换为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. 我在教程中可以找到的所有信息似乎都涉及一种数组或另一种类型,而不是如何将数据从一种更改为另一种。

They are the same: numpy.array is a function that constructs an object of type numpy.ndarray . 它们是相同的: numpy.array是一个构造numpy.ndarray类型的对象的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM