Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. The Pythonic way of checking whether a collection (string, list, set, dict, etc.) coll is non-empty is to use if coll. However, do NOT use if arr to check whether a numpy array is non-empty or not. Instead, you shoule use arr.size >0 to check whether a numpy array is non-empty or not.

  2. bottleneck is a collection of fast, NaN-aware NumPy array functions written in C.

Construct Numpy Arrays

Construct a numpy array from a list.

array([0, 1, 2, 3, 4, 5, 6])

Join a sequence of arrays along a new axis using numpy.stack.

Slicing

0
array([1, 2, 3])
(2, 3, 5)

numpy.flip

Reverse the order of elements in an array along the given axis. The shape of the array is preserved, but the elements are reordered.

numpy.where

Note: numpy.where works on both numpy.ndarray and list, however, it doesn’t work on a generator/iterator.

array([False, True, False, False, False, True])
(array([1, 5]),)
1
1

numpy.ndarray.sum

21
0

Missing Values

np.NaN, np.NAN and np.nan are the same.

  1. bottleneck is a collection of fast, NaN-aware NumPy array functions written in C.

True
True

Matrix

matrix([[1, 5]])
array([1, 5])