Numpy:判别运算取值
import numpy print("-------------一维数组运算取值------------------") vector = numpy.array([5, 10, 15, 20]) # vector == 10 equal_to_ten = (vector == 10) print (equal_to_ten) # 返回:[False True False False] print(vector[equal_to_ten]) # 返回:[10] print("---------------二维数组运算取值----------------------") matrix = numpy.array([ [5, 10, 15], [20, 25, 30], [35, 40, 45] ]) print(matrix == 25) print("------------") second_column_25 = (matrix[:,1] == 25) print (second_column_25) # 返回:[False True False],第1个是真,可用来取值 print(matrix[second_column_25, :]) # 提取第1行所有列,返回:[[20 25 30]]
结果图:
原文地址:https://www.cnblogs.com/wodexk/p/10308647.html
时间: 2024-10-12 14:33:16