pyarrow.Tensor#

classpyarrow.Tensor#

Bases:_Weakrefable

A n-dimensional array a.k.a Tensor.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])<pyarrow.Tensor>type: int32shape: (2, 3)strides: (12, 4)
__init__(*args,**kwargs)#

Methods

__init__(*args, **kwargs)

dim_name(self, i)

Returns the name of the i-th tensor dimension.

equals(self, Tensor other)

Return true if the tensors contains exactly equal data.

from_numpy(obj[, dim_names])

Create a Tensor from a numpy array.

to_numpy(self)

Convert arrow::Tensor to numpy.ndarray with zero copy

Attributes

dim_names

Names of this tensor dimensions.

is_contiguous

Is this tensor contiguous in memory.

is_mutable

Is this tensor mutable or immutable.

ndim

The dimension (n) of this tensor.

shape

The shape of this tensor.

size

The size of this tensor.

strides

Strides of this tensor.

type

dim_name(self,i)#

Returns the name of the i-th tensor dimension.

Parameters:
iint

The physical index of the tensor dimension.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>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)'dim1'>>>tensor.dim_name(1)'dim2'
dim_names#

Names of this tensor dimensions.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>tensor=pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])>>>tensor.dim_names['dim1', 'dim2']
equals(self,Tensorother)#

Return true if the tensors contains exactly equal data.

Parameters:
otherTensor

The other tensor to compare for equality.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>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)True>>>tensor.equals(tensor2)False
staticfrom_numpy(obj,dim_names=None)#

Create a Tensor from a numpy array.

Parameters:
objnumpy.ndarray

The source numpy array

dim_nameslist, optional

Names of each dimension of the Tensor.

Examples

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

Is this tensor contiguous in memory.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>tensor=pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])>>>tensor.is_contiguousTrue
is_mutable#

Is this tensor mutable or immutable.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>tensor=pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])>>>tensor.is_mutableTrue
ndim#

The dimension (n) of this tensor.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>tensor=pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])>>>tensor.ndim2
shape#

The shape of this tensor.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>tensor=pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])>>>tensor.shape(2, 3)
size#

The size of this tensor.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>tensor=pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])>>>tensor.size6
strides#

Strides of this tensor.

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>x=np.array([[2,2,4],[4,5,100]],np.int32)>>>tensor=pa.Tensor.from_numpy(x,dim_names=["dim1","dim2"])>>>tensor.strides(12, 4)
to_numpy(self)#

Convert arrow::Tensor to numpy.ndarray with zero copy

Examples

>>>importpyarrowaspa>>>importnumpyasnp>>>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)
type#