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:
(variable) a: ndarray[Unknown, Unknown]
I have no idea about these two Unknown mean.
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.
Since np.array is just np.ndarray(shape=(1,)) they have the same return type: 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With