Since I couldn't output the index extraction of np.where
during image processing at all.
I understood it while referring to the sample code of here ...
So it's a memorandum!
If you understand how to read this, you can experience aha! ?? ??
Reference sample code and output. This time the 3rd floor tensor ($ Width \ times Height \ times Channels = 2 \ times 3 \ times 4 $) It is.
a_3d = np.arange(24).reshape(2, 3, 4)
print(a_3d)
# output
# [[[ 0 1 2 3]
# [ 4 5 6 7]
# [ 8 9 10 11]]
#
# [[12 13 14 15]
# [16 17 18 19]
# [20 21 22 23]]]
print(np.where(a_3d < 5))
# output
# (array([0, 0, 0, 0, 0]), array([0, 0, 0, 0, 1]), array([0, 1, 2, 3, 0]))
Here is the output of `np.where (a_3d <5)`
array([0, 0, 0, 0, 0])
array([0, 0, 0, 0, 1])
array([0, 1, 2, 3, 0])
See it as a list of
W
H
C
To access the elements of the 3rd floor tensor
a_3d[W[0]][H[0]][C[0]] = 0
a_3d[W[1]][H[1]][C[1]] = 1
a_3d[W[2]][H[2]][C[2]] = 2
a_3d[W[3]][H[3]][C[3]] = 3
a_3d[W[4]][H[4]][C[4]] = 4
It becomes. Now you can finally read the output of ``` np.where (a_3d <5)` ``!
At first, the array was just returned, so what is this? I was wondering When you can see the shapes of rows, columns, and depths, they change to meaningful numbers. Aha experience is good ~
Recommended Posts