NumPy (Numerical Python) is an extension library of the Python language that supports a large number of dimensional array and matrix operations. In addition, it also provides a large number of mathematical function libraries for array operations.
NumPy is a very fast mathematics library, mainly used for array calculations, including:
numpy object creation:
numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)
##Name | Description | ||||||||||||||||||||||||
object | array or Nested array | ||||||||||||||||||||||||
dtype | array element Data type, optional | ||||||||||||||||||||||||
copy | Whether the object Need to copy, optional | ||||||||||||||||||||||||
order | Create array The style, C is the row direction, F is the column direction, A is any direction (default) | ||||||||||||||||||||||||
subok | Default returns an array consistent with the base class type | ||||||||||||||||||||||||
##ndmin | Specify the minimum dimension of the generated array |
Name | Description | ||||||||||||||||||||||||
##bool_ | ##Boolean data type (True or False) |||||||||||||||||||||||||
##Default integer type ( Similar to long, int32 or int64 in C language) | ##intc | ||||||||||||||||||||||||
The same as the int type of C, usually int32 or int 64 | ##intp | ||||||||||||||||||||||||
Integer type used for indexing (similar to C's ssize_t, usually still int32 or int64) | int8 | Bytes (-128 to 127) | |||||||||||||||||||||||
##int16 | Integer (-32768 to 32767) | ||||||||||||||||||||||||
##int32 | Integer (-2147483648 to 2147483647) | ||||||||||||||||||||||||
Unsigned integer (0 to 255) | |||||||||||||||||||||||||
Unsigned integer (0 to 65535) | |||||||||||||||||||||||||
Unsigned integer (0 to 4294967295) | ##uint64 | ||||||||||||||||||||||||
Unsigned integer (0 to 18446744073709551615) | |||||||||||||||||||||||||
float_ | ##Abbreviation for float64 type | ||||||||||||||||||||||||
float16 | ##Half-precision floating point number, including: 1 sign bit, 5 exponent bits , 10 mantissa digits | ||||||||||||||||||||||||
float32 | Single precision Floating point number, including: 1 sign bit, 8 exponent bits, 23 mantissa bits | ||||||||||||||||||||||||
float64
| Double precision floating point number, including: 1 sign bit, 11 exponent bits, 52 mantissa bits | ||||||||||||||||||||||||
complex_ | Abbreviation of complex128 type, that is, 128-bit complex number | ||||||||||||||||||||||||
complex64 | Complex number, representing a double 32-bit floating point number (real part and imaginary part) | ||||||||||||||||||||||||
complex128 | ##Complex number, representing a double 64-bit floating point number (real part and imaginary part )
字符 | 对应类型 |
b | 布尔型 |
i | (有符号) 整型 |
u | 无符号整型 integer |
f | 浮点型 |
c | 复数浮点型 |
m | timedelta(时间间隔) |
M | datetime(日期时间) |
O | (Python) 对象 |
S, a | (byte-)字符串 |
U | Unicode |
V | 原始数据 (void) |
dt = np.dtype(np.int32) print(dt) 输出: int32 dt = np.dtype('i4') print(dt) 输出: int32 dt = np.dtype([('age', np.int8)]) print(dt) 输出: [('age', 'i1')]
student = np.dtype([('name','S20'), ('age','i1'), ('score', 'f4')]) a = np.array([('xm', 10, 98.123456789), ('xh', 8, 99.111111111), ('xl', '9', 100)], dtype=student) print(a) 输出: [(b'xm', 10,98.12346 ) (b'xh',8,99.111115) (b'xl',9, 100.)]
The above is the detailed content of An article explaining in detail the basic data types of the Python data analysis module Numpy. For more information, please follow other related articles on the PHP Chinese website!