How to create multi-dimensional and slice variable in sympy

27 Views Asked by At

I want to create a multi-dim variable A, say of shape (3,4,5). I now want to slice this variable, say at position 2 with dim 1, so that I get A' of shape (3,5). In pseudo-python:

A_prime=A.slice(pos=2,dim=1)
print(A_prime.shape)
>>> (3,5)

I need this to do some symbolic manipulations on this unknown variable A. I have gotten to this:

dim=3
from sympy import symbols, IndexedBase, Idx

# Define symbolic symbols for the tensor components
# You can use any prefix you want, here I'm using 'T'
T = IndexedBase('T', real=True)

tdims = [Idx(symbols(f'i{i}', integer=True), i+3) for i in range(dim)]

# Create a symbolic tensor with the specified dimensions
symbolic_tensor = T[tdims]

# Print the symbolic tensor
print(symbolic_tensor)

which i think is correct so far, but now I want to slice this. I am not sure how to do this with symbolic_tensor and the documentation is not helping me much.

0

There are 0 best solutions below