python 定义numpy数组_numpy:“类数组”对象的形式定义?

NumPy中的“类数组”对象是指能够被np.array转换为ndarray的Python对象。这个过程涉及多种检查,包括是否是数组、NumPy标量、Python标量、PEP 3118缓冲接口、__array_struct__或__array_interface__接口,甚至是列表列表。如果都不符合,对象将被视为object类型的0维数组。
摘要由CSDN通过智能技术生成

事实证明,从技术上讲,几乎任何东西都是一个数组。”“Array like”更多的是说明如何解释输入,而不是限制输入是什么;如果参数被记录为Array like,NumPy将尝试将其解释为数组。

除了the nearly tautological one之外,没有类似数组的正式定义——类似数组是np.array可以转换为ndarray的任何Python对象。除此之外,你还需要学习source code。NPY_NO_EXPORT PyObject *

PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,

int max_depth, int flags, PyObject *context)

{

/*

* This is the main code to make a NumPy array from a Python

* Object. It is called from many different places.

*/

PyArrayObject *arr = NULL, *ret;

PyArray_Descr *dtype = NULL;

int ndim = 0;

npy_intp dims[NPY_MAXDIMS];

/* Get either the array or its parameters if it isn't an array */

if (PyArray_GetArrayParamsFromObject(op, newtype,

0, &dtype,

&ndim, dims, &arr, context) < 0) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值