事实证明,从技术上讲,几乎任何东西都是一个数组。”“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) {