Reputation: 3
I defined a simple function that operates on 1st and 3rd rows of a 3x3 matrix:
In [1]: from numpy import *
from sympy import Symbol
In [2]: def ifsin(mat):
mat[2,:]+=1
mat[0,:]=mat[0,:]/pow(mat[2,:],mat[2,:]>0)
return mat
In [3]:Ay=Symbol('Ay')
By=Symbol('By')
q=array([[Ay,-10 ,By],[0,0.4,1],[-1 ,-1, -1]])
q
Out[3]:
array([[Ay, -10, By],
[0, 0.4, 1],
[-1, -1, -1]], dtype=object)
In [4]:V=ifsin(q)
q
Out[4]: array([[Ay, -10.0, By],
[0, 0.4, 1],
[0, 0, 0]], dtype=object)
Why was updated 3rd row of matrix q?
Also if I eval following:
In [5]:M=ifsin(V)
q
Out[5]: array([[Ay, -10.0, By],
[0, 0.4, 1],
[1, 1, 1]], dtype=object)
Again 3rd row of q is updated!!
I tried this script on "Computable" (ipad app) and ipython notebook on ubuntu 14.04 (python 2.7.6) with the same results
Thanks in advance for your help.
updated…
I changed my function to:
def ifsin(m):
return vstack([m[0,:]/pow(m[2,:]+1,(m[2,:]+1)>0),m[1,:],m[2,:]+1])
And now all works fine. Thanks!!
Upvotes: 0
Views: 73
Reputation: 13459
You are literally asking for that update on this line:
mat[2,:]+=1
In numpy syntax, this means "update row 2 of the array named mat
by incrementing each value by 1".
Upvotes: 1