[Python] the type dtype astype Discrimination

every blog every motto: You can do more than you think.

0. Introduction

type dtype astype 小结

1. text

1. Description

name meaning
tpye() The return type of the variable
dtpye Returns the type of data in the array
astype() Change the type of data

2. The code portion

2.1 type()
import numpy as np

base_data = [1,3,4]
print(type(base_data))

Print results, variable "List" type
Here Insert Picture Description

2.2 dtype
mod_data = np.array(base_data)  # 列表转成数组
print(type(mod_data))
print(mod_data.dtype)

Print result, the variable is an array type; array data type int32
Here Insert Picture Description

2.3 astype()

Converting the int32 into float32

2.3.1 a first conversion method
mod_float_data = mod_data.astype("float32")
2.3.2 The second conversion method
mod_float_data = mod_data.astype(np.float32)
2.3.3 Test Type
print(type(mod_float_data))
print(mod_float_data.dtype)

Print the results can be seen that variable is an array type, the data type is an array float32
Here Insert Picture Description

references

[1] https://www.cnblogs.com/keye/p/11195445.html
[2] https://blog.csdn.net/qq_41621362/article/details/94405846
[3] https://blog.csdn.net/MsSpark/article/details/83831474
[4] https://www.cnblogs.com/xiaoboge/p/9682398.html
[5] https://blog.csdn.net/sinat_36458870/article/details/78946053
[6] https://www.cnblogs.com/fuhang/p/8045973.html
[7] https://blog.csdn.net/InkBamboo920/article/details/102643453

Published 39 original articles · won praise 32 · views 5778

Guess you like

Origin blog.csdn.net/weixin_39190382/article/details/104975601