I have this numpy array
a=np.array([[2*y, 0],[2*x + 1, 2*y + 4]])
I want to replace (x,y) by a value, for example (1,1).
How can I have this array with this new values in order to have something like this:
a=[[2,0],[3,6]]
I have this numpy array
a=np.array([[2*y, 0],[2*x + 1, 2*y + 4]])
I want to replace (x,y) by a value, for example (1,1).
How can I have this array with this new values in order to have something like this:
a=[[2,0],[3,6]]
You can use SymPy
(a symbolic math package) and it's Matrix (array):
>>> from sympy import Matrix
>>> from sympy.abc import x, y
>>> m = Matrix([[2*y, 0],[2*x + 1, 2*y + 4]])
>>> m
Matrix([
[ 2*y, 0],
[2*x + 1, 2*y + 4]])
>>> n = m.subs({x: 1, y: 1}) # replace variables with values
>>> n
Matrix([
[2, 0],
[3, 6]])
>>> np.array(n).astype(int) # convert to numpy array
array([[2, 0],
[3, 6]])