摘要: r = map(lambda x: x*x, [1, 2, 3]) print(list(r)) # r已经计算出来了 #[1, 4, 9] a=[["12",1], ["13",2], ["14",3], ["15",4]]a = map(lambda x:[x[0],x[1]+1], a)print(list(a))#[['12', 2], ['13', 3], ['14', 4], ['1... 阅读全文
posted @ 2018-12-06 08:33 疯狂的骆驼 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Python提供了一个非常棒的模块用于创建自定义的迭代器,这个模块就是 itertools。itertools 提供的工具相当高效且节省内存。使用这些工具,你将能够创建自己定制的迭代器用于高效率的循环。这一章,我们将一起看一看这些工具的应用实例以便理解并应用到自己的编程中去。 让我们先从几个无限迭代器的例子开始吧! 无限迭代器 itertools 包自带了三个可以无限迭代的迭代器。这意味着,... 阅读全文
posted @ 2018-12-06 08:29 疯狂的骆驼 阅读(747) 评论(0) 推荐(0) 编辑
摘要: 1234 """ 阅读全文
posted @ 2018-12-06 08:28 疯狂的骆驼 阅读(350) 评论(0) 推荐(0) 编辑
摘要: import numpy as np ret = np.arange(3) print(ret) """ 运行结果 [0 1 2] """ import numpy as npret = np.array([1,2,3,4])print(ret)"""运行结果[1 2 3 4]""" import numpy as npret = np.ones(5)print(ret)ret2 = np.z... 阅读全文
posted @ 2018-12-06 07:20 疯狂的骆驼 阅读(252) 评论(0) 推荐(0) 编辑
摘要: import numpy as np # 定义一个数组 test_array = np.array([[1 ,2 ,3] ,[3 ,4 ,5]]) ###数组简单的加减乘除法 # 加法 print(test_arra y +1) # 返回[[2 3 4][4 5 6]] # 减法 print(test_arra y -11) # 返回[[-10 -9 -8][ -8 -7 -6]] ... 阅读全文
posted @ 2018-12-06 06:56 疯狂的骆驼 阅读(647) 评论(0) 推荐(0) 编辑
摘要: # 多个列表组合成一个列表 d = [['10', '22', '34', '46'],['11', '23', '35', '47'],['18', '23', '42', '06']]print(sum(d,[]))"""['10', '22', '34', '46', '11', ' 阅读全文
posted @ 2018-12-06 05:38 疯狂的骆驼 阅读(147) 评论(0) 推荐(0) 编辑
摘要: python中itertools里的product和permutation 平时经常碰到全排列或者在n个数组中每个数组选一个值组成的所有序列等等问题,可以用permutation和product解决,很方便,所以在此mark一下吧 直接上代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ... 阅读全文
posted @ 2018-12-06 05:34 疯狂的骆驼 阅读(1570) 评论(0) 推荐(0) 编辑