Professional Documents
Culture Documents
ipynb - Colaboratory
import numpy as np
#Show
arr
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Broadcasting
Numpy arrays differ from a normal Python list because of their ability to broadcast:
#Show
arr
#Show
arr
#Show slice
slice_of_arr
#Change Slice
slice_of_arr[:]=99
arr
Data is not copied, it's a view of the original array! This avoids memory problems!
arr_copy
#Show
arr_2d
#Indexing row
arr_2d[1]
# 2D array slicing
Fancy Indexing
Fancy indexing allows you to select entire rows or columns out of order,to show this, let's quickly build out a numpy array:
↳ 6 cells hidden
Selection
Let's brie y go over how to use brackets for selection based off of comparison operators.
arr = np.arange(1,11)
arr
arr > 4
https://colab.research.google.com/drive/1EUmZO8ZStewy3dJtFvHx4wgirYW7_y-k#printMode=true 5/7
24.06.2020 г. Copy of 02-Numpy Indexing and Selection.ipynb - Colaboratory
bool_arr = arr>4
bool_arr
arr[bool_arr]
arr[arr>2]
x = 2
arr[arr>x]
Great Job!
https://colab.research.google.com/drive/1EUmZO8ZStewy3dJtFvHx4wgirYW7_y-k#printMode=true 6/7
24.06.2020 г. Copy of 02-Numpy Indexing and Selection.ipynb - Colaboratory
https://colab.research.google.com/drive/1EUmZO8ZStewy3dJtFvHx4wgirYW7_y-k#printMode=true 7/7