I am not able to figure what out what is wrong with this piece of code. Could you please help me understand what is going wrong and how to fix it?
import numpy as np
T = np.random.randint(0,5,(3,2,3))
print(T)
print(T[0,0])
print(T[0,0].sum())
T[0,0] = T[0,0]/T[0,0].sum()
print(T)
Output i get:
[[[4 1 3]
[1 4 4]]
[[0 0 4]
[2 2 2]]
[[2 4 2]
[2 1 4]]]
[4 1 3]
8
[0.5 0.125 0.375]
[[[0 0 0]
[1 4 4]]
[[0 0 4]
[2 2 2]]
[[2 4 2]
[2 1 4]]]
Output i expect:
[[[4 1 3]
[1 4 4]]
[[0 0 4]
[2 2 2]]
[[2 4 2]
[2 1 4]]]
[4 1 3]
8
[0.5 0.125 0.375]
[[[0.5 0.125 0.375]
[1 4 4]]
[[0 0 4]
[2 2 2]]
[[2 4 2]
[2 1 4]]]
Any help would be appreciated. Thanks!