Today, I started studying numpy. but it's a little bit hard for me.
Look. i don't even know how that .array works,
Well, nothing to do but accept.
array -> just making it as variable.
so that I can do work like this.
let's just
1. remember -> array the list and make it able to work with multiple codes
2. reshape -> can change the shape of the data in the array list
As I can see here, reshape(10,2) -> 10 rows, 2 values each. But I can do like this too
meaning (5,2,2) -> 5 rows(5) but each rows will have two lists(2), and give them two values each list(2)
I remember that when multiplied together, the result should be the same as the number I gave.
ex. (5 x 2 x 2 = 20) = arrange(20) -> or it will show error
Then What are the 1st dimension, 2nd dimension, and 3rd dimension?
if I type x.shape It will show (20,) -> it means it's 1D array
So, The np.array() method takes a Python list as an argument and returns a special type of array (numpy.ndarray) provided by the NumPy library.
Do I remember reshape?
(5,2,2) -> 3rd dimension
5 -> 3rd
2 -> 2nd
2 -> 1st
1. ndim
so, do see what dimension it has, use 'ndim'
Ex.
As I can see, y(it must be x)(5,2,2) is 3rd dimension
2. size
To see how many values that variable has, must use size
As I see, I can see that size can show the number of the values
3. dtype
To see the data type of the variable, must use dtype
4. nbytes
To see how many bytes the codes take, must use nbytes
6. ravel()
want to change the dimension? use ravel()
I can see now it has 1st dimension shape
7.sum() -> axis = 0, 1, 2
sum() will work the same as Python but I have to know that I also can sum based on the axis
8. mean() -> same as finding average
all added numbers / total number of the value(20)
9. max() -> finding the maximum number
10. np.zeros, one....((dimension)) or np.full((dimension), number)
or I can work like this too (y - 5,2,2,)
Arithmetic operations between the arrays
Can add more easily
Slicing
Don't have to write like [1][2.... if there are multiple dimensions, can also use like [1,2,...]
array and broadcasting
The broadcasting feature enables operations between arrays of different sizes.
There are 2 condition to use broadcasting
1. The dimensions of the two arrays must be the same or
2. The size of the dimension of the smaller array must be 1.
ex.
I cannot add a and b because of the length of the array
but If I put only one value in b,
It will work same as like this
since b also has only 'one' dimension it can be added to a. but if b has different length, it won't work
add() -> same as +
also, I can set where to save the result
empty_like() -> will empty the array