function explain
type() Return data structure type (list,dict,numpy.ndarray etc. )
dtype()
Returns the data type of the data element (int,float etc. )

remarks :1) because list,dict Can contain different data types , Therefore, it cannot be called dtype() function

           2)np.array All elements are required to be of the same data type in , So it can be called dtype() function

astype()
change np.array All data types in the data element .

remarks : It works dtype() Can be used astype()

  Test code :
import numpy as np class Myclass(): pass a = [[1,2,3],[4,5,6]] b =
{'a':1,'b':2,'c':3} c = np.array([1,2,3]) d = Myclass() e = np.linspace(1,5,10)
c_ = c.astype(np.float) f = 10 print("type(a)=", type(a)) # type(a)= <class
'list'> print("type(b)=", type(b)) # type(b)= <class 'dict'> print("type(c)=",
type(c)) # type(c)= <class 'numpy.ndarray'> print("type(d)=", type(d)) #
type(d)= <class '__main__.Myclass'> print("type(e)=", type(e)) # type(e)=
<class 'numpy.ndarray'> print("type(f)=", type(f)) # type(f)= <class 'int'>
print("type(c_)=", type(c_)) # type(c_)= <class 'numpy.ndarray'> #
print(a.dtype) ## AttributeError: 'list' object has no attribute 'dtype' #
print(b.dtype) ## AttributeError: 'dict' object has no attribute 'dtype'
print(c.dtype) ## int32 # print(d.dtype) ## AttributeError: 'Myclass' object
has no attribute 'dtype' print(e.dtype) ## float64 print(c_.dtype) ## float64 #
print(f.dtype) ## AttributeError: 'int' object has no attribute 'dtype' #
print(a.astype(np.int)) ## AttributeError: 'list' object has no attribute
'astype' # print(b.astype(np.int)) ## AttributeError: 'dict' object has no
attribute 'astype' print(c.astype(np.int)) ## [1 2 3] # print(d.astype(np.int))
## AttributeError: 'Myclass' object has no attribute 'astype'
print(e.astype(np.int)) ## [1 1 1 2 2 3 3 4 4 5] # print(f.astype(np.int)) ##
AttributeError: 'int' object has no attribute 'astype'
 

Technology
©2019-2020 Toolsou All rights reserved,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing