版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cup160828/article/details/81230229
(1)
import numpy as np
x=[1,1,1]
print(x)
print(type(x))
y=np.array(x)
print(y)
print(type(y))
print(x[x[:]==0])
print(x[x[:]==1])
print(y[y[:]==0])
print(y[y[:]==1])
print(len(y[y[:]==0]))
print(len(y[y[:]==1]))
#把以上两行的y换作x其他不变,会报错:
object of type 'int' has no len()
然后,从后两个例子可以发现:列表是有len()的,列表中的单个int元素是没有的