Huh i've been coding my own Math library in C# and i've tackled Matrix(array) operations,i defined the regular Matrix addition that requires same Matrix dimensions,but i could i add this too,thanks!
11:36 Disclaimer: Actually, you should avoid using reshape in most cases. Instead, try to always use 1) indexing with np.newaxis/None to add new "1" dimensions 2) x.squeeze(axis=N) to remove a "1" dimension in Nth position 3) x.transpose(...) or x.swapaxes(...) to change the order of axes 4) x.flat/flatten when you want to "stretch" your N-dim array into a flat 1D vector. You should only really use reshape when you really actually want to change the shape, while also rearranging the order of the elements. The reason for this recommendation is that it's very easy to make a mistake with reshape and still end up with "valid" code. For example, np.ones(2, 3).reshape(3, 2) might look like it transposes the dimensions, but actually it "reinterprets" the shape of the array. Additionally, reshape **sometimes** produces views of the original arrays and **sometimes** produces copies.
I definitely agree that user should be weary of copies and reshaping is not always what you want, users should read the docs! Using the methods you mentioned are often better for expressing intent. If you really do want a reshape but want an error to be raised when data is copied, assigning to shape is what you want instead of reshape. E.g. c = b.view(); c.shape = (2,3) will error because a copy is initiated. Note: flatten will always copy.
Thanks for explanation. I have been learning ML and neural networks on Coursera and they did not explain broadcasting as well as you did. The example of iteratively doing the adds on "incompatible" matrices and comparing to the answer given by numpy really helped a lot in my undersanding of broadcasting.
this is not correct, as the 7 cannot get squished into a 1, but the 1 dimension can be extended to 7. Otherwise the Example at the End (1,3) + (3,1) would not work and result in a (1,1) output :D
Why does "y" need to be reshaped here 7:08? Before reshaping it's (1, 3) or (3,) which is still compatible with x and results in (3, 3) shape. The result of addition is different but why use the reshaped dimensions and not the original?
Thanks! I'm using the RISE presentation plugin for Jupyter notebooks, which in turn uses the reveal.js library with the "simple" theme. You can find the definition of that theme here: github.com/hakimel/reveal.js/blob/master/css/theme/source/simple.scss, from which it seems the font you are looking for is either "Lato" or "News Cycle".
The shape of y there is (3, 1) because of the explicit ".reshape(3, 1)". Also, if the reshape call was not there, the shape would have been (3,) instead of (1, 3).
Thanks for making it intuitive! Maybe I won't have to mess around in a python console to figure stuff out every time this comes up now!
Huh i've been coding my own Math library in C# and i've tackled Matrix(array) operations,i defined the regular Matrix addition that requires same Matrix dimensions,but i could i add this too,thanks!
Great to hear!
11:36 Disclaimer: Actually, you should avoid using reshape in most cases. Instead, try to always use
1) indexing with np.newaxis/None to add new "1" dimensions
2) x.squeeze(axis=N) to remove a "1" dimension in Nth position
3) x.transpose(...) or x.swapaxes(...) to change the order of axes
4) x.flat/flatten when you want to "stretch" your N-dim array into a flat 1D vector.
You should only really use reshape when you really actually want to change the shape, while also rearranging the order of the elements.
The reason for this recommendation is that it's very easy to make a mistake with reshape and still end up with "valid" code.
For example, np.ones(2, 3).reshape(3, 2) might look like it transposes the dimensions, but actually it "reinterprets" the shape of the array.
Additionally, reshape **sometimes** produces views of the original arrays and **sometimes** produces copies.
I definitely agree that user should be weary of copies and reshaping is not always what you want, users should read the docs! Using the methods you mentioned are often better for expressing intent. If you really do want a reshape but want an error to be raised when data is copied, assigning to shape is what you want instead of reshape. E.g. c = b.view(); c.shape = (2,3) will error because a copy is initiated. Note: flatten will always copy.
My answer for the exercise at the end...
The array [[[[2]], [[3]], [[4]]]] which has shape (1, 3, 1, 1)
my anser:
np.array([2,3,4]).reshape(3,1,1)
import numpy as np
np.reshape([2,3,4], (3,1,1))
Thank you for making it interesting and easy to learn.
the forloop intuition was good. thanks!
Thank you, it really helped..
@mCoding Have you done any work in the area of Machine Learning and Deep Neural Networks?
Thanks for explanation. I have been learning ML and neural networks on Coursera and they did not explain broadcasting as well as you did.
The example of iteratively doing the adds on "incompatible" matrices and comparing to the answer given by numpy really helped a lot in my undersanding of broadcasting.
Great video. Thanks.
Excellent video, you explain it perfectly, thanks a lot ;)
A very clear explanation. Nice job
For example 3, the shape of y should be (1, 1, 1, 1, 17) rather than (1, 7, 1, 1, 17)
this is not correct, as the 7 cannot get squished into a 1, but the 1 dimension can be extended to 7. Otherwise the Example at the End (1,3) + (3,1) would not work and result in a (1,1) output :D
Why does "y" need to be reshaped here 7:08? Before reshaping it's (1, 3) or (3,) which is still compatible with x and results in (3, 3) shape. The result of addition is different but why use the reshaped dimensions and not the original?
It didnt need to be reshaped, I just wanted to show an example with that particular shape.
@@mCoding gotcha! Thank you so much. the lesson was very thorough
excellent video. btw, could you tell what the text font being used in this video?
Thanks! I'm using the RISE presentation plugin for Jupyter notebooks, which in turn uses the reveal.js library with the "simple" theme. You can find the definition of that theme here: github.com/hakimel/reveal.js/blob/master/css/theme/source/simple.scss, from which it seems the font you are looking for is either "Lato" or "News Cycle".
Thank you very much!
Awesome video! Thank you!
You explained this tech quite clear👍
At 7:19 isn't y shape == (1, 3) ? And not (3, 1) ?
The shape of y there is (3, 1) because of the explicit ".reshape(3, 1)". Also, if the reshape call was not there, the shape would have been (3,) instead of (1, 3).