| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/pyarrow.Tensor.html | [Back] [Original] |
Bases: _Weakrefable
A n-dimensional array a.k.a Tensor.
Examples
>>> import pyarrow as pa
>>> import numpy as np
>>> x = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
>>> pa.Tensor.from_numpy(x, dim_names=["dim1","dim2"])
<pyarrow.Tensor>
type: int32
shape: (2, 3)
strides: (12, 4)
Methods
|
|
|
Returns the name of the i-th tensor dimension. |
|
Return true if the tensors contains exactly equal data. |
|
Construct a Tensor from an object implementing the DLPack protocol. |
|
Create a Tensor from a numpy array. |
|
Convert arrow::Tensor to numpy.ndarray with zero copy |
Attributes
Names of this tensor dimensions. |
|
Is this tensor contiguous in memory. |
|
Is this tensor mutable or immutable. |
|
The dimension (n) of this tensor. |
|
The shape of this tensor. |
|
The size of this tensor. |
|
Strides of this tensor. |
|
Returns the name of the i-th tensor dimension.
intThe physical index of the tensor dimension.
Examples
>>> 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)
'dim1'
>>> tensor.dim_name(1)
'dim2'
Names of this tensor dimensions.
Examples
>>> 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_names
['dim1', 'dim2']
Return true if the tensors contains exactly equal data.
TensorThe other tensor to compare for equality.
Examples
>>> 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)
True
>>> tensor.equals(tensor2)
False
Construct a Tensor from an object implementing the DLPack protocol.
The input object containing array data, following the DLPack
protocol (has a __dlpack__ method).
tuple[enum.Enum, int], optionalDesignates where the resulting Tensor should reside, in the
format returned by Tensor.__dlpack_device__(). When None,
the output Tensor occupies the same device as the source.
Default: None.
Controls duplication behavior. True mandates copying; False
prohibits copying and raises BufferError if unavoidable;
None duplicates only when necessary. Default: None.
TensorA Tensor housing the data from the input object, potentially as a copy or view.
Create a Tensor from a numpy array.
numpy.ndarrayThe source numpy array
list, optionalNames of each dimension of the Tensor.
Examples
>>> import pyarrow as pa
>>> import numpy as np
>>> x = np.array([[2, 2, 4], [4, 5, 100]], np.int32)
>>> pa.Tensor.from_numpy(x, dim_names=["dim1","dim2"])
<pyarrow.Tensor>
type: int32
shape: (2, 3)
strides: (12, 4)
Is this tensor contiguous in memory.
Examples
>>> 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.is_contiguous
True
Is this tensor mutable or immutable.
Examples
>>> 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.is_mutable
True
The dimension (n) of this tensor.
Examples
>>> 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.ndim
2
The shape of this tensor.
Examples
>>> 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.shape
(2, 3)
The size of this tensor.
Examples
>>> 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.size
6
Strides of this tensor.
Examples
>>> 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.strides
(12, 4)
Convert arrow::Tensor to numpy.ndarray with zero copy
Examples
>>> 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.to_numpy()
array([[ 2, 2, 4],
[ 4, 5, 100]], dtype=int32)
| Web Proxy Viewer | New URL | Original Page |