~の意味がよくわかりません。
from matplotlib import pyplot as plt from sklearn.datasets import load_iris import numpy as np data = load_iris() print(data) features = data['data'] feature_names = data['feature_names'] target = data['target'] target_names = data['target_names'] labels = target_names[target] plength =features[:,2] is_setosa = (labels=='setosa') features = features[~is_setosa] labels = labels[~is_setosa] virginica =(labels=='virginica') max_setosa =plength[is_setosa].max() min_non_setosa = plength[~is_setosa].min() print('Maximum of setosa: {0}.'.format(max_setosa)) print('Minimum of others:{0}.'.format(min_non_setosa)) def appy_model(example): if example[2] < 2:print('Iris Setoca') else: print('Iris Virginica or Iris Versicolor')
というアイリスのデータセットをダウンロードして特徴を抽出して、ラベル付けして判定するというサンプルコードがありまして、
このコードの
features = features[~is_setosa] labels = labels[~is_setosa]
の部分の~の意味がわかりません。
~は、
ビット反転は演算子の右辺の値の各ビットに対して「1」の場合は「0」に、「0」の場合は「1」にします。
http://www.pythonweb.jp/tutorial/num/index4.html
というものであることがわかりました。
しかし、配列のインデックスを「1」の場合は「0」に、「0」の場合は「1」にすることのメリットがわかりません。
これはどういう役割なのでしょうか?
回答1件
あなたの回答
tips
プレビュー