Python学习笔记

来源:互联网 发布:视频特效素材软件 编辑:程序博客网 时间:2024/05/18 02:05
1、多维数组转置
2、a = np.array([[[1, 2, 3],[4, 5, 6],[7, 8, 9]]])
b=a.T()
TypeError: 'numpy.ndarray' object is not callable
T()用法不对
3、列表数据类型转换后,dtype显示没变的原因
arr = np.array([2.3, 3.2, -1.4, 2.3]) 
arr.astype(np.int32) 
In[36]:
arr.dtype
Out[36]:
dtype('float64')
astype方法复制了该ndarray数组,并且在复制的数组中进行转换,但是不会修改原数组。
4、匿名函数:lamda、reduce、map、filter
http://www.cnblogs.com/evening/archive/2012/03/29/2423554.html
>>> foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
>>>
>>> print filter(lambda x: x % 3 == 0, foo)
[18, 9, 24, 12, 27]
>>>
>>> print map(lambda x: x * 2 + 10, foo)
[14, 46, 28, 54, 44, 58, 26, 34, 64]
>>>
>>> print reduce(lambda x, y: x + y, foo)
5、python编程.为什么reduce函数在3.1环境下不能用了?
在Python 3里,reduce()函数已经被从全局名字空间里移除了,它现在被放置在fucntools模块里
用的话要 先引入
from functools import reduce
原创粉丝点击