I have a 12X2 array I want to reorganize into a 3x4x2 array. Specifically, I want to change
a = np.array(([1,13],[2,14],[3,15],[4,16],[5,17],[6,18],[7,19],[8,20],[9,21],[10,22],[11,23],[12,24]))
[[ 1 13]
[ 2 14]
[ 3 15]
[ 4 16]
[ 5 17]
[ 6 18]
[ 7 19]
[ 8 20]
[ 9 21]
[10 22]
[11 23]
[12 24]]`
Into a matrix that looks like this:
[[[ 1. 2. 3. 4.]
[ 5. 6. 7. 8.]
[ 9. 10. 11. 12.]]
[[ 13. 14. 15. 16.]
[ 17. 18. 19. 20.]
[ 21. 22. 23. 24.]]]
I was thinking a triple-nested for loop, but the way I coded it is not going to work. And I can't wrap my head around numpy indexing enough to figure out how to do this.
This is of course example code. I want to alter this for use to make 3 plots of the leading 3 EOFs of global precipitation on a latitude-longitude grid. The EOFs are being pulled from a 8192x8192 array and put into a 64x128x3 array. (I'm only using the first 3 columns of the large matrix. Each column is an EOF, and down each one, values are listed by longitude going along the first latitude, then listed by longitude again going along the second latitude, and so on down until the 128th latitude at the bottom of the column. Of course my array will be upside-down with respect to the base map when I finish since the first latitude is -87.something, but I plan to use np.flipud to fix it once it's finished.