```
# Python 2.7.10
# Imports #
from __future__ import print_function
from numpy import *
# Main #
def main():
a_Array = arange(27).reshape(3, 3, 3)
f_Print3dArray(a_Array)
def f_Print3dArray(a_Array):
"""&&Syntax: 3D NUMPY.NDARRAY, returns PRINT;
Desc.: Takes a NumPy 3d ARRAY and PRINTs in 'tower' form for easy reading.
Test: a_Array = arange(27).reshape(3, 3, 3)
f_Print3dArray(a_Array)
/ 2 5 8 /
/ 1 4 7 /
/ 0 3 6 /
/ 11 14 17 /
/ 10 13 16 /
/ 9 12 15 /
/ 20 23 26 /
/ 19 22 25 /
/ 18 21 24 /
"""
for i in a_Array[:,:,::-1].transpose(0,2,1): ## Get value of each col. of each last col. of each internal matrix as rows, starting with top row.
for index, j in enumerate(i): ## Get the index and value of each element in modified matrix.
print(" " * (len(i) - 1 - index) + "/ ", end="") ## Print the leading format chars.
for k in j: ## Get value of each element in row.
print(str(k).ljust( (len(str(amax(a_Array)))) + 1), end="") ## Print each element of each row with ljust to max len. of matrices max element.
print("/") ## Print trailing format chars.
print() ## Add a row between internal matrixes.
if __name__ == '__main__':
main()
```

1

Contributor0

Replies11

Views
Recommended Topics