Python:如何在numpy数组中查找数字的值? [英] Python: How to find the value of a number in a numpy array?
本文介绍了Python:如何在numpy数组中查找数字的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下数组:
a = np.array([[0,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,26,27,28,29,30,31],[32,33,34,35,36,37,38,39,],[40,41,42,43,44,45,46,47],[48,49,50,51,52,53,54,55],[56,57,58,59,60,61,62,63]])
如何编写一个将数字0-63作为输入并告诉我该数字在数组中的位置的函数?
How can I write a function that takes a number 0-63 as input, and tells me where that number is in the array?
示例:function(0)返回a [0,0];函数(13)返回a [5,1]
example: function(0) returns a[0,0]; function(13) returns a[5,1]
推荐答案
最短的方法(以相反的顺序为您提供索引)是
The shortest way (gives you the indices in oposite order) is
np.argwhere(a==13)
给予:
array([[1, 5]])
这篇关于Python:如何在numpy数组中查找数字的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文