最近在学机器学习,但对代码中的type()
和dtype
这两个分不太清,它们之间的区别在哪里啊?求详解,十分感谢。 😅
%matplotlib inline
import d2lzh as d2l
from mxnet.gluon import data as gdata
import sys
import time
mnist_train = gdata.vision.FashionMNIST(train=True)
mnist_test = gdata.vision.FashionMNIST(train=False)
feature, label = mnist_train[0]
print(label)
print(type(label))
print(label.dtype)
数据类型对象(numpy.dtype类的实例)描述了如何解释与数组项对应的固定大小的内存块中的字节。 它描述了数据的以下几个方面:
而type()作为保留字,是一个重要函数,不用基于numpy。
Python 中 type、 dtype、 astype 用法区别
type() 属于 python 内置函数,可返回参数对象的数据类型或数据结构类型
dtype 出自 numpy.dtype ,用于查看数组的数据元素类型时需用 arr.dtype 属性的形式
astype 出自 numpy.chararray.astype ,改变 arr 中所有数据元素的类型为指定的 dtype 格式,返回一个修改后的 arr
https://zhuanlan.zhihu.com/p/366934271