Issue
I'm looking over the docs and I still can't figure out how the third parameter operates.
np.r_['0,2,0', [1,2,3], [4,5,6]]
output:
array([[1],
[2],
[3],
[4],
[5],
2)
np.r_['1,2,0', [1,2,3], [4,5,6]]
output:
array([[1, 4],
[2, 5],
[3, 6]])
The first parameter is the axis, second is the number of dimensions and third according to the docs means " which axis should contain the start of the arrays which are less than the specified number of dimensions"
Here are the docs:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.r_.html
Thank you.
Solution
Maybe a simple example can clear things up:
b=np.arange(3)
np.r_['0,2,0', b, b]
# array([[0],
# [1],
# [2],
# [0],
# [1],
# [2]])
np.r_['0,2,1', b, b]
# array([[0, 1, 2],
# [0, 1, 2]])
We are concatenating b
a 1d array with itself. The second number specifies that it should be made 2d before it gets stacked on itself as specified by the first number. Now there are two ways to make a shape (3,) array 2d: either make it (3, 1) (first example) or make it (1, 3) (second example). The third number specifies where the first original dimension (i.e. 3) goes in the 2d array.
Answered By - Paul Panzer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.