29、关于文件输入参数,可以通过sysy.argv查看,但!Don’t implement option parsing yourself. Use modules such as optparse
, argparse
or :mod`docopt`.
30、os.listdir('.')
31、importlib.reload(demo)用于重加加载更改后新的模块
32、if __name__ == '__main__':
33、you should not write very long lines that span over more than (e.g.) 80 characters. Long lines can be broken with the \
character
-------------------------------------------------------------------------------------------------------------------
34、a = np.array(...) a.ndim, a.shape, len(a), np.arange(), np.linspace(), np.ones(tuple), np.zeros(tuple), np.eye()
35、
a = np.random.rand(4) # uniform in [0, 1]
36、
b = np.random.randn(4) # Gaussian
37、
a = np.random.randint(0, 21, 15)a[a % 3 == 0] = -1
38、
a = np.arange(10) >>> idx = np.array([[3, 4], [9, 7]]) >>> idx.shape (2, 2) >>> a[idx] array([[3, 4], [9, 7]])
39、
= np.arange(10000)
>>> %timeit a + 1
10000 loops, best of 3: 24.3 us per loop
>>> l = range(10000)
>>> %timeit [i+1 for i in l]
1000 loops, best of 3: 861 us per loop
40、Array multiplication is not matrix multiplication:, ## c.dot(c)
41、
np.array_equal(a, b)
42、
x = np.array([[1, 1], [2, 2]]) >>> x array([[1, 1], [2, 2]]) >>> x.sum(axis=0) # columns (first dimension) array([3, 3]) >>> x[:, 0].sum(), x[:, 1].sum() (3, 3) >>> x.sum(axis=1) # rows (second dimension) array([2, 4]) >>> x[0, :].sum(), x[1, :].sum() (2, 4)