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,
c Language implementation 《 Student management system 》 No hole is the future of mobile phone ? There are still many problems to be solved Junior , A little sense , Just for mutual encouragement How to use Vue Used in Echarts Visual Library The 11th Blue Bridge Cup Java The second provincial competition B Group part Python- be based on OpenCV Contour fill for flooding algorithm hole filling 【C#】 The realization of student achievement information management system List Common interview questions in the collection and simple ideas China Mobile Science Popularization : Why do mobile networks call “ Cellular mobile network ”【Golang Basic series 10 】Go language On conditional sentences if