摘要:
例题2.30代码 import numpy as np a = np.array([[0, 3, 4], [1, 6, 4]]) b = a.sum() c1 = sum(a) c2 = np.sum(a, axis = 0) c3 = np.sum(a, axis = 1, keepdims = 阅读全文
摘要:
例题2.29代码 import numpy as np a = np.arange(16).reshape(4, 4) b = np.vsplit(a, 2) print('行分割: \n', b[0], '\n', b[1]) c = np.hsplit(a, 4) print('列分割:: \n 阅读全文
摘要:
例题2.28代码 import numpy as np a = np.arange(16).reshape(4,4) b = np.floor(5 * np.random.random((2, 4))) c = np.ceil(6 * np.random.random((4, 2))) d = np 阅读全文
摘要:
例题2.27代码 import numpy as np a = np.arange(16).reshape(4,4) b = a[1][2] c= a[1, 2] d = a[1:2, 2:3] x = np.array([0, 1, 2, 1]) print(a[x == 1]) 阅读全文
摘要:
例题2.26代码 import numpy as np a = np.ones(4, dtype= int) b = np.ones((4,), dtype= int) c = np.ones((4,1)) d = np.zeros(4) e = np.empty(3) f = np.eye(3) 阅读全文
摘要:
例题2.25代码 import numpy as np a1 = np.array([1,2,3,4]) a2 = a1.astype(float) a3 = np.array([1,2,3,4], dtype = float) print(a1.dtype); print(a2.dtype); p 阅读全文
摘要:
例题2.24代码 s1 = [str(x) for x, y in zip(['v'] * 4, range(1, 5))] s2 = list(zip('abcd', range(4))) print(s1); print(s2) 阅读全文
摘要:
例题2.23代码 def filter_non_unique(L): return [item for item in L if L.count(item) == 1] a = filter_non_unique([1, 2, 3, 4, 5]) print(a) 阅读全文
摘要:
例题2.22代码 a = filter(lambda x: x > 10, [1, 11, 2, 45, 7, 6, 13]) b = filter(lambda x: x.isalnum(), ['abc', 'xy12', '***']) print(list(a)); print(list(b 阅读全文
摘要:
例题2.21代码 import random x = random.randint(1e5, 1e8) y = list(map(int, str(x))) z = list(map(lambda x, y: x%2 == 1 and y%2 == 0, [1, 3, 2, 4, 1], [3, 2 阅读全文