Python Day 17 – Slicing and Dicing with Numpy

Good morning y’all…

I learned:

That you can take slices of rows/columns (for instance matrix[0] is first row, matrix[1] is second row, and so on). You can also make a .copy of a slice rather than reference the original, although I’m not sure the significance of that quite yet.

To only get odd or even rows/columns:

arr[::2,:]    #odd rows

arr[1::2,:]   #even rows

arr[:,::2]    #odd cols

arr[:,1::2]   #even cols

(credit to Ilja S. on Stack Overflow)

Also, you can mask arrays in python very similarly to VFX (I do some VFX work). It’s essentially assigning a boolean value for whether to show a value or not, which is essentially the same as creating a black/white mask to hide parts of an image when compositing VFX! Yay I love when things connect.

A little thing I learned:

There were several times I tried to run code with nothing happening, and then realized that I can’t just define an array but need to write the name of the array after it’s definition to get it to show.

I’m still confused on:

What’s the importance of making a copy of a slice rather than reference it?

There’s one portion of the course I’m taking which goes into fancy indexing stuff… for instance feeding in specific indices to access in array format (to be clear I just typed those words but don’t have an idea what I’m saying). For example:

arr = np.arange(100)
ind = [2, 5, 30]

print(‘Array indexing: ‘, arr[ind])

^this returns the same ind values -> 2,5,30 … which makes me confused as to what it did.

Anywho, these are questions we shall figure out! Onwards we go in this wondrous journey of coding and snakes and pies and all that good jazz.

Did you know you can create folders in Spotify? If you right click on a computer you can make em and it updates to your phone too. God I love organization.

Leave a Reply

Discover more from

Subscribe now to keep reading and get access to the full archive.

Continue reading