Learn NumPy

August 11, 2020

Introduction

Numpy!

Arrays

Arrays!

Operations

Arithmetic. Perform scalar arithmetic with arrays.

Sum, subtraction, product and division of same length arrays will make the operation index based, meaning first item from A plus first item from B / first item from A times first item from B, etc

Operations between arrays and a scalar will make the operation to all items in the array.

You can do lots of operations for all items in an array, like max, min, log, sin, sqrt etc

Indexing

Indexing with number, just as regular Python Indexing with [start?:end?]

Broadcasting: you can broadcast a reassignment for items in an array: arr[0:5] = 88. Slices are by reference, so if you change them, the original array will also be modified. To copy, arr_copy = arr.copy()

Indexing in two dimensions: matrix[row_number, col_number] or matrix[row_number][col_number]

Conditional selection

Make a assertion regarding your array, save it in a variable and index the array with the assertion array of booleans.

arr = np.arange(0,11)
bool_arr = arr > 4
arr[bool_arr]