Issue
What are the input order for a numpy multi-dimensional array?
When I use np.ones((3,2,2)) I expect 3 arrays or size 2x2 but reading on other posts (the numpy documentation wasn't clear) some claim that the first two inputs are row and column with the 3rd input being the dimension I want to span.
Basically I want to stack multiple arrays infront of each each to create a multi-dimensional tensor similar to how torch works with [Channel, Row, Columns]
Thanks
Solution
Normally, numpy lays out an array of size (A, B, C) as A groups of BxC elements, and each of those BxC elements are B groups of C elements. Hence x[1,1,1] will be next to x[1, 1, 2] in memory.
However you can say, np.ones((3, 4, 5), order='F')
, which tells numpy to use Fortran onrder instead of C order. In this case, x[1, 1, 1] will be adjacent to x[2, 1, 1] in memory. This is not the default.
Answered By - Frank Yellin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.