numpy中常见的数据类型如下。在使用的时候依据数据范围选择合适的数据类型,避免占用不必要的内存。
Numpy type | C type | Description |
np.int8 | int8_t | Byte (-128 to 127) |
np.int16 | int16_t | Integer (-32768 to 32767) |
np.int32 | int32_t | Integer (-2147483648 to 2147483647) |
np.int64 | int64_t | Integer (-9223372036854775808 to 9223372036854775807) |
np.uint8 | uint8_t | Unsigned integer (0 to 255) |
np.uint16 | uint16_t | Unsigned integer (0 to 65535) |
np.uint32 | uint32_t | Unsigned integer (0 to 4294967295) |
np.uint64 | uint64_t | Unsigned integer (0 to 18446744073709551615) |
np.intp | intptr_t | Integer used for indexing, typically the same as ssize_t |
np.uintp | uintptr_t | Integer large enough to hold a pointer |
np.float32 | float | |
np.float64 / np.float_ | double | Note that this matches the precision of the builtin python float. |
np.complex64 | float complex | Complex number, represented by two 32-bit floats (real and imaginary components) |
np.complex128 / np.complex_ | double complex | Note that this matches the precision |