简体   繁体   English

如何从数组中选择一个数字并告诉您Python中的列和行?

[英]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.

相关问题 如何从数据库列的python中的数组中仅选择元素 - How do you select just the element from an array in python from a database column 如何从python矩阵的每一列中选择具有最多最小值的行? - How do I select a row with most number of minimum values out of each column from a matrix in python? 在Python中,如何生成数组的排列,其中每个列和行只有一个元素? - In Python, how do you generate permutations of an array where you only have one element from each column and row? Python 按数组列分组,按行号分区 - Python group by array column and partition by row number 您如何 Python 中 SQL 列中的 select 值 - How do you select values from a SQL column in Python 您如何通过在 Python MySQL 中输入列名来 select 单行? - How do you select a single row by inputting a column name in Python MySQL? 如何通过 python 中 select 列右侧的每行中的 nan 数对 dataframe 进行子集化? - How to subset a dataframe by the number of nans in each row to the right of a select column in python? 如何使用python识别几个匹配的列值以选择行并将值从anothe表分配给新列 - How to identify several matching column values to select row and assign value from anothe table to new column with python python numpy:如何识别数组中列数最少的列或行 - python numpy: how to identify column or row that has the smallest number of ones in an array 如何在python / numpy中切片多维数组,以选择特定的行,列和深度? - How to slice a multidimensional array in python/numpy in a way to select specific row, column and depth?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM