pyarrow.fixed_shape_tensor#

pyarrow.fixed_shape_tensor(DataTypevalue_type,shape,dim_names=None,permutation=None)#

Create instance of fixed shape tensor extension type with shape and optionalnames of tensor dimensions and indices of the desired logicalordering of dimensions.

Parameters:
value_typeDataType

Data type of individual tensor elements.

shapetuple orlist ofintegers

The physical shape of the contained tensors.

dim_namestuple orlist ofstrings, defaultNone

Explicit names to tensor dimensions.

permutationtuple orlistintegers, defaultNone

Indices of the desired ordering of the original dimensions.The indices contain a permutation of the values[0,1,..,N-1] whereN is the number of dimensions. The permutation indicates which dimensionof the logical layout corresponds to which dimension of the physical tensor.For more information on this parameter seeFixed shape tensor.

Returns:
typeFixedShapeTensorType

Examples

Create an instance of fixed shape tensor extension type:

>>>importpyarrowaspa>>>tensor_type=pa.fixed_shape_tensor(pa.int32(),[2,2])>>>tensor_typeFixedShapeTensorType(extension<arrow.fixed_shape_tensor[value_type=int32, shape=[2,2]]>)

Inspect the data type:

>>>tensor_type.value_typeDataType(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.Tabletensor_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 namesof 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 withpermutation:

>>>tensor_type=pa.fixed_shape_tensor(pa.int8(),(2,2,3),...permutation=[0,2,1])>>>tensor_type.permutation[0, 2, 1]