0

I have two numpy arrays pcar and out_list.

[[  5.80084178e-05   1.20779787e-02  -2.65970238e-02]
 [ -1.36810406e-02   6.85722519e-02  -2.60280724e-01]
 [  4.21996519e-01  -1.43644036e-01   2.12904690e-01]
 [  3.03098198e-02   1.50170659e-02  -1.09683402e-01]
 [ -1.50776089e-03   7.22369575e-03  -3.71181228e-02]
 [ -3.04448275e-01  -3.66987035e-01   1.44618682e-01]
 [ -1.46744916e-01   3.47112167e-01   3.09550267e-01]
 [  1.16567762e-03   1.72858807e-02  -9.39297514e-02]
 [  1.25896836e-04   1.61310167e-02  -6.00253128e-02]
 [  1.65062798e-02   1.96933143e-02  -4.26540031e-02]
 [ -3.78020965e-03   7.51770012e-03  -3.67852984e-02]]

and

[[-0.01368104  0.06857225 -0.26028072]
 [ 0.42199652 -0.14364404  0.21290469]]

I want to subtraction of out_list from pcar and want to get two different arrays with the results.

Example:

First Array as-

[[ 5   8    5]
 [ 1   2    4]
 [ 7   6    1]]

and Second Array as-

[[ 1   6   2]
 [ 4   5   3]]

then result should be

[[ 4   2   3]
 [ 0   -4   2]
 [ 6    0  -1]]

and

[[ 1   3   2]
 [-3  -3   1]
 [ 3   1  -2]]
7
  • 2
    I don't get how to subtract between 11 x 3 and 2 x 3 matrices? Do you mean two result that 11 x 3 - 1 x 3 and 11 x 3 - 1 x 3? Commented Apr 5, 2014 at 15:16
  • @mskimm Yup I want the results of 11 x 3 - 1 x 3 and 11 x 3 - 1 x 3. Commented Apr 5, 2014 at 15:19
  • It is ambiguous what you mean by subtraction here. From a mathematical point of view it is impossible to subtract a 2x3 matrix form a 11x3 one. Commented Apr 5, 2014 at 15:20
  • Please include a simplified example of what you want. Commented Apr 5, 2014 at 15:21
  • @jojo I want that 1st row of 2 x 3 array should be deleted from all the rows of 11 x 3 array and so on. So that I will get two atrix of size 11 x 3 Commented Apr 5, 2014 at 15:23

1 Answer 1

1

This should do the job:

import numpy as np
a = np.array([[1,2,3],[10,20,30],[100,200,300]])
b = np.array([[1,2,3],[10,20,30]])
result_list = [np.subtract(a,b_x) for b_x in b]
#now you can use the result_list:
print result_list[0]
#>>> [[  0   0   0]
#     [  9  18  27]
#     [ 99 198 297]]

print result_list[1]
#>>>[[ -9 -18 -27]
#    [  0   0   0]
#    [ 90 180 270]]
Sign up to request clarification or add additional context in comments.

3 Comments

Can I access these two arrays differently so I can do more operations on it?
I'm not completely sure if I understand what you'd like to do, but will edit my answer, just a sec...
consider accepting the answer if it works for you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.