简体   繁体   English

np.ndarray 的类型参数

[英]type parms of np.ndarray

when I type当我输入

import numpy as np

a = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float64)

pylance tells me a's type is: pylance 告诉我 a 的类型是:

(variable) a: ndarray[Unknown, Unknown]

I have no idea about these two Unknown mean.我不知道这两个Unknown的意思。

Referrer to the stub file存根文件的引用者

class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):

I still don't know about it.我仍然不知道。 How can I fill them?我该如何填写?

Those unknown refer to the shape and data type of the array created.那些unknown是指创建的数组的形状和数据类型。

Since np.array is just np.ndarray(shape=(1,)) they have the same return type: ndarray[_ShapeType@ndarray, _DType_co@ndarray]由于np.array只是np.ndarray(shape=(1,))它们具有相同的返回类型: ndarray[_ShapeType@ndarray, _DType_co@ndarray]

Therefore your code should work like this:因此,您的代码应该像这样工作:

import numpy as np

a: np.ndarray[int, np.dtype[np.float64]] = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float64)

where int refers to the size tuple datatypes and np.dtype[np.float64] the array data's type其中int是指大小元组数据类型, np.dtype[np.float64]是数组数据的类型

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

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