更多机器学习知识请查收于: https://blog.csdn.net/weixin_45316122/article/details/109854595
Trick:纯demo,心在哪里,结果就在那里(ipython notebook代码演示)
5 import numpy as np a = np.array([[1,2,3,4],[2,3,4,5]]) print (a) [[1 2 3 4] [2 3 4 5]] 9 import numpy as np a = np.array([1,2,3,4],ndmin = 3) print (a) [[[1 2 3 4]]] 11 import numpy as np dt = np.dtype(np.int32) print dt File "<ipython-input-11-96707a7b8c9c>", line 3 print dt ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(dt)? 13 import numpy as np x = np.array([1,2,3,4,5,6]) print (x.flags) C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : True WRITEABLE : True ALIGNED : True WRITEBACKIFCOPY : False UPDATEIFCOPY : False 16 import numpy as np x = np.empty([3,2], dtype = int) print(x) [[1 2] [3 4] [5 6]] 41 import numpy as np s = 'Hello World' a = np.frombuffer(s, dtype = 'S1') print (a) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-41-30ab03270588> in <module> 1 import numpy as np 2 s = 'Hello World' ----> 3 a = np.frombuffer(s, dtype = 'S1') 4 print (a) AttributeError: 'str' object has no attribute '__buffer__' 42 # 从列表中获得迭代器 import numpy as np list = range(5) it = iter(list) # 使用迭代器创建 ndarray x = np.fromiter(it, dtype = float) print (x) [0. 1. 2. 3. 4.] 3 import numpy as np x = np.linspace(10,20,5) print(x) [10. 12.5 15. 17.5 20. ] 3 import numpy as np #显示该数组中(0,0),(1,1),(2,0)位置的元素 x = np.array([[1, 2], [3, 4], [5, 6]]) y = x[[0,1,2],[0,1,0]] print(y) [1 4 5] 7 import numpy as np a = np.arange(8).reshape(2,4) print ('原数组:') print (a) print ('\n') print ('调用 ravel 函数之后:') print (a.ravel()) print ('\n') print ('以 F 风格顺序调用 ravel 函数之后:') print (a.ravel(order = 'F') ) 原数组: [[0 1 2 3] [4 5 6 7]] 调用 ravel 函数之后: [0 1 2 3 4 5 6 7] 以 F 风格顺序调用 ravel 函数之后: [0 4 1 5 2 6 3 7] 17 import time s= time.time() time.sleep(2) print(s) p = time.time() print(p) q = p s print(q) 1568959868.6637378 1568959870.6643877 2.000649929046631 26 import time s = 1568959868.6637378 t = time.localtime(s) w = time.strftime("%Y-%m-%d %H:%M:%S",t) print(w) 2019-09-20 14:11:08