Re: data science tutorials

hi again,
I'm here with another tutorial, and that is how we can use numpy.

what is numpy?

when we were installing it, I've told you that it is being used to do neumerical computation
now, the question is, how to do neumerical computation, and use it?
what advantages does numpy have that a normal python list doesn't?

numpy arrays

consider this list:

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

if i want to multiply all of it for example by three, what should i do?
one might say that you can loop through that list and do your computation.
now what if i want to multiply that list by

[3, 4, 5]

?
then i have to loop through both lists which at least makes our code slower in terms of computation in normal lists

creating numpy arrays

lets open up your python (python command in your command shell would suffice) and create the following array:

import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

now, we have an array, which I want to tell you what we can do with it

print(a)

prints the array on the console

print(a.dtype)

prints the type of the array (which in here is int32)

print(a.shape)

prints the shape of the array as a tuple (here we have a 3x3 matrix (more on that later))
now, back to the dtype.
I want to create that same array with for example float32 datatype. now, what should i do?

a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.float32)

if i print a.dtype, I'll get float32
same with int64, float64 and so on
also, print the array. what is the difference?
exactly. I got floating point numbers instead.
as the number after the decimal is 0, numpy didn't print that part and instead it finished with a dot.
now, what is your idea on doing computation with numpy?

doing computation with numpy

create another array for example named b like this:

b = np.array([[2, 4, 6]])

and multiply that with a:

print(a*b)

if you print b.shape, it is (1, 3) so they can be multiplied together
let me tell you how this is calculated
since a is 3x3, and b is 1x3, we can multiply them:
b will be multiplied to each row respectively.
but if b.shape becomes for example 1x4, then we can't do the multiplication
now, multiply a by itself:

print(a*a)

exactly!. since a.shape is 3x3, they can be multiplied together easily.
each number in a index will be multiplied by it's position on the same index
we can do other math operations like we did with multiplication

print(a.T)

what happened?
this will transpose our array.
[[1., 4., 7.],
[2., 5., 8.],
[3., 6., 9]]
you can see that the array is easily transposed
as we can expect,, for example if we transpose a 3x2 matrix, we'll get a 2x3 matrix.
(matrices, vectors, etc will be taught on linear algebra)
numpy has many operations like dot (np.dot),, mean (np.mean), standard deviation (np.std), etc
and, this concludes our today's tutorial
let me know if you have any questions.



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : zakc93 via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : ogomez92 via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Off-topic room : Donavin . Liebgott via Audiogames-reflector

Reply via email to