【dataquest学习】numpy计算

直接用“==”判断numpy各项是否与base值相同,不需要for循环

countries_canada=(world_alcohol[:,2]=='Canada')
years_1984=(world_alcohol[:,0]=='1984')
countries_canada,years_1984
matrix = np.array([[5, 10, 15], 
                [20, 25, 30],
                [35, 40, 45]])
second_column_25 = (matrix[:,1] == 25)
print(second_column_25,matrix[second_column_25])

得到结果:

[False  True False] [[20 25 30]]

你可能感兴趣的:(【dataquest学习】numpy计算)