Answer the question
In order to leave comments, you need to log in
How to create a symbolic matrix?
It is necessary to create a character matrix of arbitrary size. I wrote a function, but something went wrong. Since this is part of a large code, I do not intend to completely sympy with numpy.
Here is the code:
import numpy as np
from sympy import *
shape = (4,4)
X = np.empty(shape)
for i in range(shape[0]):
for j in range(shape[1]):
X[i][j] = Symbol("x"+'_{'+str(i*10+j+11)+'}')
224 if result.is_number and result.as_real_imag()[1]:
225 raise TypeError("can't convert complex to float")
--> 226 raise TypeError("can't convert expression to float")
227
228 def __complex__ (self):
TypeError: can't convert expression to float
Answer the question
In order to leave comments, you need to log in
Because np.empty() is an array of numbers (float), and you shove characters into it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question