| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/../api/../generated/pyarrow.fixed_shape_tensor.html | [Back] [Original] |
Section Navigation
Create instance of fixed shape tensor extension type with shape and optional names of tensor dimensions and indices of the desired logical ordering of dimensions.
DataTypeData type of individual tensor elements.
tuple or list of integersThe physical shape of the contained tensors.
tuple or list of strings, default NoneExplicit names to tensor dimensions.
tuple or list integers, default NoneIndices of the desired ordering of the original dimensions.
The indices contain a permutation of the values [0, 1, .., N-1] where
N is the number of dimensions. The permutation indicates which dimension
of the logical layout corresponds to which dimension of the physical tensor.
For more information on this parameter see
Fixed shape tensor.
Examples
Create an instance of fixed shape tensor extension type:
>>> import pyarrow as pa
>>> tensor_type = pa.fixed_shape_tensor(pa.int32(), [2, 2])
>>> tensor_type
FixedShapeTensorType(extension<arrow.fixed_shape_tensor[value_type=int32, shape=[2,2]]>)
Inspect the data type:
>>> tensor_type.value_type
DataType(int32)
>>> tensor_type.shape
[2, 2]
Create a table with fixed shape tensor extension array:
>>> arr = [[1, 2, 3, 4], [10, 20, 30, 40], [100, 200, 300, 400]]
>>> storage = pa.array(arr, pa.list_(pa.int32(), 4))
>>> tensor = pa.ExtensionArray.from_storage(tensor_type, storage)
>>> pa.table([tensor], names=["tensor_array"])
pyarrow.Table
tensor_array: extension<arrow.fixed_shape_tensor[value_type=int32, shape=[2,2]]>
----
tensor_array: [[[1,2,3,4],[10,20,30,40],[100,200,300,400]]]
Create an instance of fixed shape tensor extension type with names of tensor dimensions:
>>> tensor_type = pa.fixed_shape_tensor(pa.int8(), (2, 2, 3),
... dim_names=['C', 'H', 'W'])
>>> tensor_type.dim_names
['C', 'H', 'W']
Create an instance of fixed shape tensor extension type with permutation:
>>> tensor_type = pa.fixed_shape_tensor(pa.int8(), (2, 2, 3),
... permutation=[0, 2, 1])
>>> tensor_type.permutation
[0, 2, 1]
Copyright 2016-2026 Apache Software Foundation.
Apache Arrow, Arrow, Apache, the Apache logo, and the Apache Arrow project logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.
Created using Sphinx 9.1.0.
Built with the PyData Sphinx Theme 0.20.0.
| Web Proxy Viewer | New URL | Original Page |