NumPy
Table of Contents
- https://pabloinsente.github.io/intro-numpy-fundamentals
h5py
- It lets you store huge amounts of numerical data, and easily manipulate that data from NumPy. For example, you can slice into multi-terabyte datasets stored on disk, as if they were real NumPy arrays. Thousands of datasets can be stored in a single file, categorized and tagged however you want.
Sort rows of 2D matrix #
a = np.array([[9, 8, 7], [6, 5, 4], [3, 2, 1]])
a
# array([[9, 8, 7],
# [6, 5, 4],
# [3, 2, 1]])
a[:, a[0, :].argsort()]
# array([[7, 8, 9],
# [4, 5, 6],
# [1, 2, 3]])
Double advanced indexing #
a = np.array([[1, 2], [3, 4]])
idxs_1 = np.array([1])
idxs_2 = np.array([0])
# does not work
a[idxs_1][idxs_2] = np.array([9, 9])
print(a) # [[1 2] [3 4]]
# works
a[idxs_1[idxs_2]] = np.array([9, 9])
print(a) # [[1 2] [9 9]]