python - Print array element with False value -
in python, how can print elements false value? here code:
import numpy np height = [1.65, 1.75, 1.71, 1.72, 1.69, 1.68, 1.67, 1.70] weight = [60, 65, 88, 59, 78, 77, 79, 72] # calculate , print bmis bmi = np.array(weight) / np.array(height) print("the values of bmis:", bmi) # create array bmi status (true/false) less 40 true_false_bmi = np.array(bmi) < 40 # print out whole true_false_bmi array true/false print("status of bmis (criteria -> less 40):", true_false_bmi) # print out bmis less 40 print("bmis less 40:", bmi[true_false_bmi])
upto working fine. want print bmis above 40. have tried following codes , not working:
# print out bmis of baseball players bmi above 40 i.e., false elements of true_false_bmi array. print("bmis above 40:", bmi[!true_false_bmi]) print("bmis above 40:", bmi[not true_false_bmi])
you can use ~
operator negation in numpy
.
print("bmis above 40:", bmi[~true_false_bmi])
Comments
Post a Comment