numpy的一些用法

今天看到keras遷移學習的demo程序,如下:
(x_train, y_train), (x_test, y_test) = mnist.load_data(r'E:\pythonProject\proj1\hhy_keras\遷移學習\mnist.npz')

# create two datasets one with digits below 5 and one with 5 and above
x_train_lt5 = x_train[y_train < 5]
y_train_lt5 = y_train[y_train < 5]
x_test_lt5 = x_test[y_test < 5]
y_test_lt5 = y_test[y_test < 5]

x_train_gte5 = x_train[y_train >= 5]
y_train_gte5 = y_train[y_train >= 5] - 5
x_test_gte5 = x_test[y_test >= 5]
y_test_gte5 = y_test[y_test >= 5] - 5

不是很理解索引裏做的比較

自己寫了個例子如下
a = [1,2,3,4,5,6,7,8,8,9,0,12,11,21,35,90]
c = numpy.asarray(a, dtype=numpy.int32)
b = c[c >= 5]
print(b)

打印
[ 5  6  7  8  8  9 12 11 21 35 90]

看到打印就知道這用法了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章