I would like to create a 3D matrix of a certain size by calculating the value for each combination of indices. Each value in the matrix will be symbolic.
What I have tried so far:
import numpy as np import sympy as sp var1 = np.arange(1,10,2) var2 = np.arange(1,10,2) var3 = np.arange(20,50,5) myMatrix = np.zeros(shape = (len(var1), len(var2), len(var3))) t = sp.symbols('t') for ii in range(len(var1)): for jj in range(len(var2)): for kk in range(len(var3)): myMatrix[ii][jj][kk] = var1[ii] * var2[jj] * var3[kk] * t
This gives me an error:
TypeError: cannot convert expression to float
as I understand it, due to the union of numpy and sympy. So I tried:
myMatrix = sp.MatrixSymbol('temp', len(var1), len(var2), len(var3))
instead:
myMatrix = np.zeros(shape = (len(var1), len(var2), len(var3)))
and received an error message:
TypeError: new () takes exactly 4 arguments (5 data)
To summarize, I ask the question: how can I create a 3D matrix with any variables inside to be able to use it in a nested loop that involves a symbolic calculation?
(This is my first post in this community, so please let me know if I did something wrong.)