摘要:
例题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 阅读全文
摘要:
例题2.20代码 x1 = "abcde" x2 = list(enumerate(x1)) for ind, ch in enumerate(x1): print(ch) 阅读全文
摘要:
例题2.19代码 import numpy.random as nr x1 = list(range(9,21)) nr.shuffle(x1) x2 = sorted(x1) x3 = sorted(x1, reverse=True) x4 = sorted(x1, key = lambda it 阅读全文