[英]How to select a number from an array and tell you the column and row in Python?
If I have, for example, an array of 5 * 5 that has as numbers the list from 1 to 25 such that: 例如,如果我有一个5 * 5的数组,该数组具有从1到25的数字列表,则:
X = list (range (1,26))
Dimension = 5
A = np.zeros ((dimension, dimension))
N = 0
For i in range (dimension):
For j in range (dimension):
A [i] [j] = x [n]
N = n + 1
And I want python tell me the column and row where this number 16, how is it done? 我想让python告诉我这个数字16的列和行,它是如何做到的?
To find 16
in : 在以下位置找到16
:
a = [[ 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10.]
[ 11. 12. 13. 14. 15.]
[ 16. 17. 18. 19. 20.]
[ 21. 22. 23. 24. 25.]]
Do: 做:
np.where(a == 16)
Output: 输出:
(array([3]), array([0]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.