列表是可以改变的,能够增加或减少,(append和del函数)
2.元组
>>> zoo=('wolf','elephant','penguin')
>>> zoo.count('penguin')
1
>>> zoo.index('penguin')
2
>>> zoo.append('pig')
Traceback (most recent call last):
AttributeError: 'tuple' object has no attribute 'append'
>>> del zoo[0]
Traceback (most recent call last):
TypeError: 'tuple' object doesn't support item deletion
3.数组(array)
使用numpy中的函数np.array()。 list中的数据类不必相同的,而array的中的类型必须全部相同。在list中的数据类型保存的是数据的存放的地址,简单的说就是指针,并非数据,这样保存一个list就太麻烦了,例如list1=[1,2,3,'a']需要4个指针和四个数据,增加了存储和消耗cpu。
numpy中封装的array有很强大的功能,里面存放的都是相同的数据类型
我们再来看看二维的处理方式
print c[1:2]# c[1:2].shape-->(1L, 3L) print c[1:2][0] # shape-->(3L,)
[[4 4 5]] [4 4 5]print c[1] print c[1:2]
[4 4 5] [[4 4 5]]print c[1][2] print c[1:4] print c[1:4][0][2]
reference
http://blog.youkuaiyun.com/liyaohhh/article/details/51055147
http://blog.youkuaiyun.com/yasi_xi/article/details/38384047