Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : Matrices subtraction similar to numpy #439

Closed
rohitjoshi opened this issue Apr 18, 2018 · 5 comments
Closed

Question : Matrices subtraction similar to numpy #439

rohitjoshi opened this issue Apr 18, 2018 · 5 comments

Comments

@rohitjoshi
Copy link

rohitjoshi commented Apr 18, 2018

In numpy y-mu returns as below

mu=[-1.35900258, -0.00274826, -0.60259734]
y=[[-1.16850298],
 [-0.71405641],
 [-1.84973747]]

r = y-mu
print("y-mu=" + str(r))
y-mu = [[ 0.1904996  -1.16575472 -0.56590564]
 [ 0.64494618 -0.71130814 -0.11145907]
 [-0.49073488 -1.8469892  -1.24714013]]

How do I achieve same in ndarray?

mu=[-0.25304218713684945, 0.12751433863551823, 0.3773315624850666]
y= [[0.41651350674857823]]
y-mu gives error 
thread 'main' panicked at 'ndarray: could not broadcast array from shape: [3] to: [1, 1]'
@vbarrielle
Copy link
Contributor

You probably want to use broadcasting.

@rohitjoshi
Copy link
Author

I tried few ways without any success. Would appreciate your help.

@jturner314
Copy link
Member

See #437 for a similar question, in particular this response. Basically, one solution is to broadcast the left array (y in your example) to the size of the result, and then perform the operation.

@jturner314
Copy link
Member

@rohitjoshi Do you have any more questions about this? Otherwise, I'll close this issue.

@rohitjoshi
Copy link
Author

No, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants