Skip to content

Instantly share code, notes, and snippets.

@doubledare704
Created June 17, 2016 20:09
Show Gist options
  • Save doubledare704/23e5f865bbb4bc2e9f78d8897f3cd3ec to your computer and use it in GitHub Desktop.
Save doubledare704/23e5f865bbb4bc2e9f78d8897f3cd3ec to your computer and use it in GitHub Desktop.
import numpy as np
n = 10
a = np.random.randint(0, 10, (n, n, n))
print("All matrix: {0}".format(a))
columns = a.sum(axis=0)
rows = a.sum(axis=1)
z_s = a.sum(axis=2)
t = columns.max()
print("Max value in columns {0}".format(t))
i, j = np.unravel_index(columns.argmax(), columns.shape)
print("Element in[{0}, {1}, {2}]".format(i, j, 0))
t = rows.max()
print("Max value in rows {0}".format(t))
i, j = np.unravel_index(rows.argmax(), rows.shape)
print("Element in[{0}, {1}, {2}]".format(j, i, 0))
t = z_s.max()
print("Max value in z-dim {0}".format(t))
i, j = np.unravel_index(z_s.argmax(), z_s.shape)
print("Element in[{0}, {1}, {2}]".format(0, j, i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment