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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| import numpy as np
res_0 = np.array([1, 2, 3, 4, 5])
np.asarray([[1, 2, 3], [4, 5, 6]])
np.arange(start, stop, step, dtype)
np.random.rand(4, 3)
np.random.randn(2, 4)
np.random.randint(low=1, high=10, size=(3, 4), dtype='I')
np.random.uniform(low=1.0, high=10.0, size=(3, 4))
res_1 = np.array([[1, 2, 3], [4, 5, 6]])
res_sum = np.sum(res_1) res_sum_col = np.sum(res_1, axis=0) res_sum_row = np.sum(res_1, axis=1) res_sum_condition = np.sum(res_1 == 1)
res_1_list = res_1.tolist()
res_1.astype(numpy.float32)
np.empty((2, 3)) np.zeros((2, 3)) np.ones((2, 3)) np.eye(3)
res_1 > 3 res_1[res_1 > 3]
arr = np.array([1, 2, 3, 4, 5, 6]) res_idx = np.where(arr > 3)
condition = np.array([True, False, True, False, True]) x = np.array([1, 2, 3, 4, 5]) y = np.array([6, 7, 8, 9, 10]) res = np.where(condition, x, y)
tmp = np.reshape(np.arange(start=0, stop=9, step=1), (3, -1))
tmp = np.array([[1, 2, 3], [4, 5, 6]]) for ele in tmp.flat: print(ele)
tmp_flatten = np.array([[1, 2, 3], [4, 5, 6]]).flatten()
np.array([[1, 2, 3], [4, 5, 6]]).T
arr = np.array([1, 2, 3]) arr_expand = np.expand_dims(arr, axis=0)
arr_squeeze = np.squeeze(arr_expand, axis=0)
tmp_a = np.array([1, 2, 3]) tmp_b = np.array([4, 5, 6]) concated_res = np.concatenate((tmp_a, tmp_b), axis=0)
stack_res = np.stack((tmp_a, tmp_b), axis=0)
tmp = np.array([[1, 2, 3], [4, 5, 6]]) tmp_split = np.split(tmp, indices_or_sections=3, axis=1)
tmp = np.array([[1, 2, 3], [4, 5, 6]]) tmp_append = np.append(tmp, [[7, 8, 9]], axis=0)
tmp = np.array([[1, 2, 2], [4, 2, 6]]) tmp_unique = np.unique(tmp)
|