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,
The 11th Blue Bridge Cup python The real topic of the University Group National Games JavaSwing To achieve a simple Lianliankan games 【Spring Source code analysis 】42-@Conditional Detailed explanation element-ui Step on pit record 2019PHP Interview questions ( Continuously updated )PHPJava Misunderstanding —— Method overloading is a manifestation of polymorphism ? First issue 500 100 million , Set up a new Department , What is Tencent going to do ? Google chrome The browser can't open the web page , But what if other browsers can open it ? Regression of dependent variable order categories (R language )【Golang Basic series 10 】Go language On conditional sentences if