Wu Yuxiong - natural born Numpy library study notes: NumPy data types

The following table lists the common NumPy basic types. 
Name Description 
bool_ Boolean data type (True or False) 
the int_ default integer type (Long similar to the C language, or Int64 int32) 
as intc and C int type, int generally int32 or 64 
integer for indexing intp type (C-like ssize_t, under normal circumstances remains int32 or Int64) 
int8 byte ( -128 to 127 ) 
Int16 integer ( -32768 to 32767 ) 
int32 integer ( -2147483648 to 2147483647 ) 
Int64 integer ( -9223372036854775808 to 9223372036854775807 ) 
uint8 unsigned integer (0 to 255 ) 
UInt16 unsigned integer (0 to 65535 ) 
UInt32 unsigned integer (0 to 4294967295 ) 
UInt64 unsigned integer (0 to18446744073709551615 ) 
float_ float64 type short 
float16 half-precision floating-point format, comprising: a sign bit, five exponent bits and 10 mantissa bits 
float32 single precision floating point number, comprising: a sign bit, eight exponent bits and 23 mantissa bit 
float64 double precision floating point, comprising: a sign bit, 11 exponent bits and 52 mantissa bits 
complex_ complex128 type short, i.e., 128 bit complex 
complex64 complex, represents a double 32 bit floating point (real number part and imaginary number part) 
complex128 complex, bis represents 64-bit floating-point (real number part and imaginary number part)
Data type objects (DTYPE) 
DTYPE objects are constructed using the following syntax: 
Object - Data type of the object to be converted to 
align = left - and when it is true, the pad field of a C-like structure. 
Copy - copy dtype object, if false, the built-in data type is a reference to the object
Import numpy NP AS
 # scalar type 
dt = np.dtype (np.int32)
 Print (dt)
Import numpy NP AS
 # int8, Int16, Int32, Int64 four data types can use string 'i1', 'i2', 'i4', 'i8' replaced 
dt = np.dtype ( ' I4 ' )
 Print (dt)
Import numpy NP AS
 # byte sequence denoted by 
dt = np.dtype ( ' <I4 ' )
 Print (dt)
# First creates a structured data types 
Import numpy NP AS 
dt = np.dtype ([( ' Age ' , np.int8)]) 
 Print (dt)
# The data type is applied ndarray objects 
Import numpy NP AS 
dt = np.dtype ([( ' Age ' , np.int8)]) 
A = np.array ([(10,), (20 is,), (30, )], DTYPE = dt) 
 Print (A)
# Type field names may be used to access the actual age column 
Import numpy NP AS 
dt = np.dtype ([( ' age ' , np.int8)]) 
A = np.array ([(10,), (20 is, ), (30,)], DTYPE = dt) 
 Print (A [ ' Age ' ])
import numpy as np
student = np.dtype([('name','S20'), ('age', 'i1'), ('marks', 'f4')]) 
print(student)
import numpy as np
student = np.dtype([('name','S20'), ('age', 'i1'), ('marks', 'f4')]) 
a = np.array([('abc', 21, 50),('xyz', 18, 75)], dtype = student) 
print(a)

Guess you like

Origin www.cnblogs.com/tszr/p/12228666.html