Numpy int64() 函数参数?

太空尘埃

不知道为什么我找不到这个,但以下是什么意思?

hashvalue_byte_size = len(bytes(np.int64(42).data))

从左到右,我一般会说这描述了 np.int64(42).data 中字节的长度。

所以字节长度是8。

我认为 'np.int64()' 表示 (-9223372036854775808 到 9223372036854775807) 中的整数或 (0 到 18446744073709551615) 中的无符号整数

或者前缀“np”是否使 int64() 成为其他东西?

最后,“42”代表什么?.data 是什么意思?

保利

从内到外解析这样的表达式是最有意义的:

In [189]: np.int64(42)
Out[189]: 42
In [190]: type(_)
Out[190]: numpy.int64
In [191]: np.int64(42).data
Out[191]: <memory at 0x7f7dc41a82e8>
In [192]: type(_)
Out[192]: memoryview
In [193]: np.int64(42)
Out[193]: 42
In [194]: type(_)
Out[194]: numpy.int64
In [195]: np.int64(42).data
Out[195]: <memory at 0x7f7dcc05cac8>
In [196]: type(_)
Out[196]: memoryview
In [197]: bytes(np.int64(42).data)
Out[197]: b'*\x00\x00\x00\x00\x00\x00\x00'
In [198]: len(_)
Out[198]: 8

查看具有一个或多个元素的 numpy 数组可能更有意义:

In [204]: np.array(42)
Out[204]: array(42)
In [205]: _.dtype
Out[205]: dtype('int64')
In [206]: np.array(42).data
Out[206]: <memory at 0x7f7dcc054780>
In [207]: bytes(np.array(42).data)
Out[207]: b'*\x00\x00\x00\x00\x00\x00\x00'
In [208]: bytes(np.array([42,43]).data)
Out[208]: b'*\x00\x00\x00\x00\x00\x00\x00+\x00\x00\x00\x00\x00\x00\x00'

数组对象具有属性和一个databuffer. 该缓冲区存储数据,在本例中为每个元素的 8 字节整数。bytes(...data)刚刚产生缓冲器的字节串表示。

tobytes方法相同

In [209]: np.array([42,43]).tobytes()
Out[209]: b'*\x00\x00\x00\x00\x00\x00\x00+\x00\x00\x00\x00\x00\x00\x00'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将 numpy int64 转换为列表

无法区分dtype int64的wrt numpy数组?

优雅地将int64的numpy数组转换为datetime64的numpy数组

为什么 Numpy 的 int 数据类型与 Numpy 的 int64 数据类型的类型不同?

计算的 Numpy 数组问题,int 类型,int32 与 int64

二维 numpy 数组不会从 int64 隐式转换为 float64

是否可以将numpy int64数组转换为int类型

numpy from函数的参数

导入函数参数numpy

为什么 md5 算法在散列时接受 numpy 的 int64 而不是整数?

如何在索引来自 int64 numpy 数组的列表中打印值?

如何停止numpy meshgrid将默认数据类型设置为int64

pandas / numpy int64(python 3.6)中发生意外的32位整数溢出

'numpy.int64'类型的参数不可迭代

无法转换“ Int64”类型的值?到预期的参数类型“ Int”

如何创建仅接受int32或int64的函数

无法将numpy dtypes转换为其本机python类型(将int64转换为int)

2 参数 numpy where 函数

BigQueryOperator:对于参数类型:DATE,INT64,operator =没有匹配的签名

无法转换“字符串”类型的值?到预期的参数类型'Int64'Swift iOS

在int / long / etc中使用“ in”参数修饰符(别名Int32 / Int64非只读结构)

当使用SimpleJSON传递给函数时,Int64会更改值

为什么我们需要Tensorflow的损失函数中的MNIST标签使用`int64`?

使用math.erf()将意外值分配给dtype('int64')时,numpy数组未更新

NumPy:将 int64 值存储在具有 dtype float64 的 np.array 中然后将其转换回整数是否安全?

numpy mean函数的参数“ a”如何工作?

具有整数参数的分段numpy函数

将 numpy 数组作为函数参数传递

对于参数类型:STRING、INT64,运算符 > 没有匹配的签名。支持的签名:BigQuery 中的 ANY > ANY