using array-scalar type
import numpy as np
dt = np.dtype(np.int32)
print (dt)
#int8, int16, int32, int64 can be replaced by equivalent string 'i1', 'i2','i4', etc.
import numpy as np
dt = np.dtype('i4')
print (dt)
using endian notation
import numpy as np
dt = np.dtype('i4')
print (dt)
#The following examples show the use of structured data type.
#Here, the field name and the corresponding scalar data type is to be declared.
first create structured data type
import numpy as np
dt = np.dtype([('age',np.int8)])
print (dt)
now apply it to ndarray object
import numpy as np
dt = np.dtype([('age',np.int8)])
a = np.array([(10,),(20,),(30,)], dtype = dt)
print (a)
file name can be used to access content of age column
import numpy as np
dt = np.dtype([('age',np.int8)])
a = np.array([(10,),(20,),(30,)], dtype = dt)
print (a['age'])
#The following examples define a structured data type called student
#with a string field 'name', an integer field 'age' and a float field 'marks'.
#This dtype is applied to ndarray object.
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)
thanxxxxxxxxxx
Auf dieser Seite können Sie das Online-Video python numpy data types || data types || dtype || numpy ||python ||Ak mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer CSE TECH'S 22 Dezember 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,871 Mal angesehen und es wurde von 17 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!