[英]Numpy types for Cython users
I'm not quite understand what is the difference between numpy.{typename}, numpy.npy_{typename} and numpy.{typename}_t when i use them from Cython code? 我不太明白numpy。{typename},numpy.npy_ {typename}和numpy。{typename} _t之间的区别是什么,当我从Cython代码中使用它们时?
ie what is the difference in these types: 即这些类型的区别是什么:
# test.pyx
cimport numpy as np
import numpy as np
np.float32
np.npy_float32
np.float32_t
As i understand it now: first type is dynamic, ie Cython will generate some code to detect size of that type at runtime. 正如我现在所理解的那样:第一种类型是动态的,即Cython将生成一些代码以在运行时检测该类型的大小。 Two other types are static, ie code which uses it will be compiled with predefined sizes of each type.
另外两种类型是静态的,即使用它的代码将使用每种类型的预定义大小进行编译。 Please correct me.
请指正。
Additional link: https://docs.scipy.org/doc/numpy/reference/c-api.dtype.html#c-type-names 其他链接: https : //docs.scipy.org/doc/numpy/reference/c-api.dtype.html#c-type-names
np.float32
is NumPy's TypeDescriptor, which is a Python object which can be queried and passed to NumPy to construct arrays just as in Python. np.float32
是NumPy的TypeDescriptor,它是一个Python对象,可以像在Python中一样查询并传递给NumPy来构造数组。
np.npy_float32
is a C type, which can be used wherever a C type is needed, eg np.npy_float32
是一种C类型,可以在需要C类型的任何地方使用,例如
cdef np.npy_float32 x = 1.902
cdef np.ndarray[np.npy_float32, ndim=2] A = np.zeros((3, 4), dtype=np.float32)
np.float32_t
is simply a typedef of np.npy_float32
which can be used as a shorthand. np.float32_t
是一个简单的类型定义的np.npy_float32
可以用来作为简写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.