pyarrow.Tensor#

pyarrow.Tensor\(n\)pyarrow.Array,也就是张量。

import pyarrow as pa
import numpy as np

x = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
y = pa.Tensor.from_numpy(x, dim_names=["dim1","dim2"])
y
<pyarrow.Tensor>
type: int32
shape: (2, 3)
strides: (12, 4)

pyarrow.Tensor.dim_name()(self, i)#

返回第 i 个张量维度的名称。

import pyarrow as pa
import numpy as np
x = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
tensor = pa.Tensor.from_numpy(x, dim_names=["dim1","dim2"])
tensor.dim_name(0), tensor.dim_name(1)
('dim1', 'dim2')

pyarrow.Tensor.equals()(self, Tensor other)#

如果张量包含完全相同的数据,则返回 True

import pyarrow as pa
import numpy as np
x = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
tensor = pa.Tensor.from_numpy(x, dim_names=["dim1","dim2"])
y = np.array([[2, 2, 4], [4, 5, 10]], np.int32)
tensor2 = pa.Tensor.from_numpy(y, dim_names=["a","b"])
tensor.equals(tensor), tensor.equals(tensor2)
(True, False)
x1 = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
x2 = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
tensor1 = pa.Tensor.from_numpy(x1, dim_names=["dim11","dim12"])
tensor2 = pa.Tensor.from_numpy(x2, dim_names=["dim21","dim22"])
tensor1.equals(tensor2), tensor1 == tensor2
(True, True)

pyarrow.Tensor.to_numpy()#

x = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
tensor = pa.Tensor.from_numpy(x, dim_names=["dim1","dim2"])
tensor.to_numpy()
array([[  2,   2,   4],
       [  4,   5, 100]], dtype=int32)