BrisPy / talks

Brisbane Python User Group
15 stars 1 forks source link

Introduction to numpy/pandas #46

Closed kaiw closed 4 years ago

kaiw commented 4 years ago

This would most likely be a general slot talk aimed at introducing the audience to numpy & pandas packages, what they're used for, and a general demonstration of how to use them.

kaiw commented 4 years ago

Given that our usual slots are ~25 minutes, I'm not sure whether it makes sense to do both numpy & pandas, or whether it would be better to go into slightly more depth on just one of them.

@rancoxu Would you be interested in doing this at the next meetup on Wednesday, November 13?

rancoxu commented 4 years ago

i'm not sure, if going a bit deeper on numpy i might talk a bit about its application in image/sound processing? pandas is more plain i suppose, more basics to cover and 25 min sounds about right.

rancoxu commented 4 years ago

time's great! I'll leave Nov 13th blank for this session.

kaiw commented 4 years ago

i'm not sure, if going a bit deeper on numpy i might talk a bit about its application in image/sound processing?

I think it's often good to have an application domain to provide motivation and examples, so sounds interesting to me!

pandas is more plain i suppose, more basics to cover and 25 min sounds about right.

Agreed.

I think you could easily talk about either. Let me know which topic you'd prefer to present, and I'll lock it in.

rancoxu commented 4 years ago

haha cool numpy it is! I'll compose a tentative lecture script by tmrw and maybe have a bit of discussion with you, is that ok?

kaiw commented 4 years ago

Sounds good!

rancoxu commented 4 years ago

Hi Kai, How are you? So I have compiled a tentative tutorial script on numpy please have a look at it. However, I usually spend 2 hours with my students on it. In that case, I think I might wanna go straight to audio and image manipulation after briefly going over the numpy basics. If the feedback is mostly positive, I will probably cover more basics in a later session? All the best, Ranco

On Fri, Oct 11, 2019 at 9:19 AM Kai Willadsen notifications@github.com wrote:

Sounds good!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BrisPy/talks/issues/46?email_source=notifications&email_token=AIJ6JJ3FJA3GRN6U5FNGTDDQN62BHA5CNFSM4I7SP3OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA6IKQA#issuecomment-540837184, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIJ6JJ44M373SXTWUUG7SQDQN62BHANCNFSM4I7SP3OA .

rancoxu commented 4 years ago

Hi Kai, How are you? So I have compiled a tentative tutorial script on numpy please have a look at it. However, I usually spend 2 hours with my students on it. In that case, I think I might wanna go straight to audio and image manipulation after briefly going over the numpy basics. If the feedback is mostly positive, I will probably cover more basics in a later session? All the best, Ranco

kaiw commented 4 years ago

So I have compiled a tentative tutorial script on numpy please have a look at it. However, I usually spend 2 hours with my students on it.

Yeah, I can see that there's a lot of content here! I think for our audience, the challenge is that you'll need to introduce the extreme basics (i.e., what is numpy, what is a numpy array/matrix and how does it differ from a python list, etc.) and then give examples of why someone would use it.

In that case, I think I might wanna go straight to audio and image manipulation after briefly going over the numpy basics. If the feedback is mostly positive, I will probably cover more basics in a later session?

I think I'd suggest not making this too much of an API tutorial, but rather focus more on explaining how to do/think about things with numpy, if that makes sense?

Are you thinking of presenting this as a series of jupyter notebooks demos? The audio & image manipulation sounds like it would make a good motivating example.

rancoxu commented 4 years ago

ok no problem i'll simplify it and yes jupyter notebook will make it easier to display the result along explanation

kaiw commented 4 years ago

@rancoxu I've scheduled you in for the general slot but with a generic talk title (see https://github.com/BrisPy/talks). If you want to send me updated details that would be cool.

rancoxu commented 4 years ago

@kaiw Hi Kai, time's perfect for me. i'm a bit caught up in interviews and tutoring recently but i'll come up with a new script be4 Thur. is that ok?

kaiw commented 4 years ago

Yeah that's all good. You're welcome to send things through for feedback, but you also don't have to. I'm happy either way.

rancoxu commented 4 years ago

import numpy as np import os import sounddevice as sd import matplotlib.pyplot as plt import cv2

change cwd

os.chdir(os.path.dirname(os.path.realpath(file)))

Basics

print('' 50, 'Basics', '' 50) a = np.arange(10).reshape(2, 5) print(a)

b = np.array([[1, 2, 3], [4, 5, 6]], dtype='int16') # by default 'int32' print(b) print(b[0, :])

Get dim

print('' 50, 'Get Dimension', '' 50) print(a.ndim)

Get shape

print('' 50, 'Get Shape', '' 50) print(a.shape)

Access/change specific location

print('' 50, 'Access/change specific location', '' 50) a = np.array([[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14]]) print(a)

Get a specific element

print(a[0, 1]) print(a[0, -2])

Get a row/col

print('' 50, 'Get a row/col', '' 50) print(a[1, :]) print(a[:, 0])

[start:end:step] index

print('' 50, 'Indexing with steps', '' 50) print(a[0, 0:-1:2])

Initialization

print('' 50, 'Initialization', '' 50) a = np.zeros((2, 3)) b = np.ones((3, 4)) c = np.eye(4) d = np.identity(4) print(a, '\n\n', b, '\n\n', c, '\n\n', d)

Random array

print('' 50, 'Random array', '' 50) a = np.random.rand(3, 3) print(a) b = np.random.random_sample(a.shape) print(b) c = np.random.randint(1, 3, size=(2, 3)) print(c)

Matrix Calcs

print('' 50, 'Array Calculations', '' 50) a = np.array([1, 2, 3, 4]) print(a + 2) print(a - 2) print(a / 2) print(a * 2)

By default elementwise

b = np.array([1, -1, 1, -1]) print(a + b) print(a ** 2) print(np.sin(a))

Reorganizing arrays

print('' 50, 'Re-organizing array', '' 50) be4 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) print(be4)

size must match

after = be4.reshape((8, 1)) print(after)

audio manipulation

print('' 50, 'Audio manipulation', '' 50)

set parameters

sampling_time = 1 frequency = 44100

generate x values that later on subbed into sin() to emulate sound wave

x = np.arange(0, sampling_time * frequency) wave = np.sin(x) sd.play(wave, samplerate=frequency, blocking=True)

image manipulation

random dots

print('' 50, 'Image manipulation', '' 50) pixels_gray = np.random.randint(0, 255, (128, 128)) plt.imshow(pixels_gray, cmap='gray', vmin=0, vmax=255) plt.grid(False) plt.show()

image fiddling

img=cv2.imread('pup.jpg')

convert RGB to Grayscale

img_gray=cv2.cvtColor(img,cv2.COLOR_RGB2GRAY) print(img_gray.shape) print(img_gray) plt.imshow(img_gray,cmap='gray') plt.show()

rancoxu commented 4 years ago

Yeah that's all good. You're welcome to send things through for feedback, but you also don't have to. I'm happy either way.

Hi Kai, can you please have a look at this simplified version and let me know if there's anything that needs to change? Thx a lot. Ranco

kaiw commented 4 years ago

Looks good to me! Honestly, it's also pretty hard to judge a presentation from a workbook.

I think my main comment here would be that I think it's easy when doing a notebook-based presentation to go through the content very quickly, just because you already know it well, and there's an assumption that people can follow the on-screen code fairly easily. If you're already planning to talk through the lines here a bit (e.g., in the Basics section I assume you'll talk through the data types aspect of numpy arrays) then I think this seems good!

rancoxu commented 4 years ago

Alright! I'll add that in when doing presentation! Thanks for ur advice. Best wishes, Ranco

On Fri, Nov 1, 2019, 09:45 Kai Willadsen notifications@github.com wrote:

Looks good to me! Honestly, it's also pretty hard to judge a presentation from a workbook.

I think my main comment here would be that I think it's easy when doing a notebook-based presentation to go through the content very quickly, just because you already know it well, and there's an assumption that people can follow the on-screen code fairly easily. If you're already planning to talk through the lines here a bit (e.g., in the Basics section I assume you'll talk through the data types aspect of numpy arrays) then I think this seems good!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BrisPy/talks/issues/46?email_source=notifications&email_token=AIJ6JJ4UUW6AMPTNHHN3PEDQRNUYXA5CNFSM4I7SP3OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECZSQXY#issuecomment-548612191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIJ6JJ6GXXOUO5PC6P72KTDQRNUYXANCNFSM4I7SP3OA .

rancoxu commented 4 years ago

@kaiw Kai just wondering what time would this session be?

kaiw commented 4 years ago

It's scheduled for 6:50pm, since you'd be the general track talk (the beginner talk goes first). See https://www.meetup.com/Brisbane-Python-User-Group/events/265543641/

Is that okay for you?

On Sat, 2 Nov 2019 at 14:29, Ranco notifications@github.com wrote:

@kaiw https://github.com/kaiw Kai just wondering what time would this session be?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BrisPy/talks/issues/46?email_source=notifications&email_token=AAAAPSY3EYGQSIMUW57EZJLQRT63FA5CNFSM4I7SP3OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC4TRYY#issuecomment-549009635, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAPSYPA5GMJSWEN7EANRTQRT63FANCNFSM4I7SP3OA .

rancoxu commented 4 years ago

Yes that's perfect for me!

On Sat, Nov 2, 2019, 14:32 Kai Willadsen notifications@github.com wrote:

It's scheduled for 6:50pm, since you'd be the general track talk (the beginner talk goes first). See https://www.meetup.com/Brisbane-Python-User-Group/events/265543641/

Is that okay for you?

On Sat, 2 Nov 2019 at 14:29, Ranco notifications@github.com wrote:

@kaiw https://github.com/kaiw Kai just wondering what time would this session be?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/BrisPy/talks/issues/46?email_source=notifications&email_token=AAAAPSY3EYGQSIMUW57EZJLQRT63FA5CNFSM4I7SP3OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC4TRYY#issuecomment-549009635 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AAAAPSYPA5GMJSWEN7EANRTQRT63FANCNFSM4I7SP3OA

.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BrisPy/talks/issues/46?email_source=notifications&email_token=AIJ6JJ44NI7R4NQ7ZW4DPJLQRT7HVA5CNFSM4I7SP3OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC4TTHY#issuecomment-549009823, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIJ6JJ6VHCVEVBTIABXMPO3QRT7HVANCNFSM4I7SP3OA .

rancoxu commented 4 years ago

@kaiw hi Kai, i might be late for about 30min today as i get off work at 6pm and usually it takes about 15min to go to river lab. Plz lemme know if there's anything i can do beforehand and sorry for the inconvenience.

kaiw commented 4 years ago

@rancoxu Don't worry about it, that'll be fine! The break for snacks and socialising is usually about 6:30, so come find one of the organisers when you arrive (we'll probably be obvious, but if I can't find you I'll wait up the front). If you're slightly late, that's okay too... we'll just let people chat for a bit longer during the break.

rancoxu commented 4 years ago

sounds great!

On Wed, Nov 13, 2019, 06:35 Kai Willadsen notifications@github.com wrote:

@rancoxu https://github.com/rancoxu Don't worry about it, that'll be fine! The break for snacks and socialising is usually about 6:30, so come find one of the organisers when you arrive (we'll probably be obvious, but if I can't find you I'll wait up the front). If you're slightly late, that's okay too... we'll just let people chat for a bit longer during the break.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BrisPy/talks/issues/46?email_source=notifications&email_token=AIJ6JJ4V3UIBND7O6SHRLYTQTMHQLA5CNFSM4I7SP3OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED32ZBI#issuecomment-553102469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIJ6JJZEWSPW5Z55H2NIKL3QTMHQLANCNFSM4I7SP3OA .

kaiw commented 4 years ago

Thanks for doing this!