Array subtraction and/or reshaping
I would like some help with a problem. In Python:
a=array([2,2])
b=ones((2,10))
I would like to know if there is a function that allows me to subtract b-a to have an arra开发者_如何学Goy of 2x10 full of -1.
I can do it one with 1D arrays, I just wanted to know if it is possible to do with 2D arrays.
Thanks
Add a new dimension to a
:
b - a[:,None]
where a[:,None]
becomes array([[2], [2]])
, a 2x1 array which you can substract from a 2x10 array and get a 2x10 array full of -1.
You want to have an array of 2x10 full of -1.
Why don't you just do like this:
b = np.ones((2, 10)) * -1
array([[-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.],
[-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.]])
精彩评论