attribute dtype
In [49]: arr=np.arange(5) In [50]: arr Out[50]: array([0, 1, 2, 3, 4]) In [51
]: arr.dtypeOut[51]: dtype('int32')
function dtype( )

effect : Structured array types and use them

grammar :numpy.dtype(object, align, copy)

parameter meaning
Object An object that is converted to a data type .
Align If true, The interval is added to the field , Make it similar C The structure of .
Copy Generate dtype A new copy of the object , If flase, The result is a reference to the built-in data type object . In [53]: np.dtype(np.int32) Out[
53]: dtype('int32')
Structured data type
In [54]: student = np.dtype([('name','S20'), ('age', 'i1'), ('marks', 'f4')])
In [55]: print student [('name', 'S20'), ('age', 'i1'), ('marks', '<f4')]
Apply it to ndarray object
In [56]: a = np.array([('abc', 21, 50),('xyz', 18, 75)], dtype = student) In [
57]: print a [('abc', 21, 50.) ('xyz', 18, 75.)]
The file name can be used to access name,age,marks The contents of the column
In [60]: print a['name'] ['abc' 'xyz'] In [61]: print a['marks'] [ 50. 75.] In
[62]: print a['age'] [21 18]
astype( ) function

effect : shifting clause dtype
In [66]: arr=np.arange(5) In [67]: arr.dtype Out[67]: dtype('int32') In [68]:
float_arr=arr.astype(np.float64)In [69]: float_arr.dtype Out[69]: dtype('float64
')In [70]: float_arr Out[70]: array([ 0. 1. 2. 3. 4.])

Technology
©2019-2020 Toolsou All rights reserved,
QT Delete directory and file Java aggregate ------LinkedHashMap Underlying principle I've been drinking soft water for three years ? What is the use of soft water and water softener Java Xiao Ming A+B About wechat payment body( Product description ) Problems encountered Digital rolling lottery program 3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! Huawei Mate 40 Pro+ 5G exposure : Leica film lens , Ceramic body What's the difference in server prices ? Operators Website visitors' mobile phone number capture