Numpy Notes – Easiest Explanation – 2022

Machine Learning Projects

Hey guys, hope all is well. These days, I was constantly thinking that how could I contribute even more to the community rather than just posting projects. Then suddenly this thought came into my mind, that why am I not sharing my self-made notes which have helped me throughout my Data Science journey.

So from now onwards I will also be sharing my self-made handwritten notes for last-minute revisions before an interview. In today’s blog, I will be sharing my Numpy notes. So without any further due.

Let’s go through the Numpy notes…

numpy
  • NumPy stands for Numerical Python.
  • The reason it is so fast is because it is having bindings to the C library.
  • np.array(list) will convert a list to a NumPy array.
  • np.arange(start, stop, step) will create an array from start to stop with a step size of step.
  • np.zeros(shape) will create an array of provided shape with all elements as zeros. The array can be 1D, 2D, 3D, etc.
  • np.linspace(start, stop, n) will give n eually spaced number of points between start and stop.
  • np.eye(n) will give a nXn Identity matrix. An identity matrix is having all elements as zeros except diagonals which are 1s.
  • np.random.rand(shape) will give an array with random elements from a uniform distribution between 0 and 1.
  • np.random.randn(shape) will give an array with random elements from a normal distribution about 0.
  • We can use array.size to check whether it is 1D or 2D or 3D, etc.
numpy
  • np.random.randint(start, stop, n) will give n number of points between the range of start and stop. One thing to note here is that start is inclusive but the stop is exclusive.
  • arr.reshape(shape) will reshape the array arr in the new shape provided.
  • np.max(arr) gives the maximum element in the array arr.
  • np.min(arr) gives the minimum element in the array arr.
  • np.argmax(arr) gives the index of the maximum element in the array arr.
  • np.argmin(arr) gives the index of the minimum element in the array arr.
  • arr.shape gives the shape of the array.
  • I have provided some slicing examples also for a better understanding of slicing operation in NumPy.
numpy
  • While slicing in NumPy, the data is not copied anywhere, it is just a view of the data out of the full array. If we change something in the slice, it will ultimately also get changed in the original array.
  • arr.copy() creates a copy of the array arr. Here new memory is allocated to the new copy. Changes done in the copy are not reflected back in the original array.
numpy
  • Broadcasting operation.
  • np.sqrt(arr) will calculate square root of all the elements of the array.
  • np.exp(arr) will calculate exponential of all the elements of the array.
  • np.sin(arr) will calculate sin of all the elements of the array.
  • np.cos(arr) will calculate cos of all the elements of the array.
  • np.log(arr) will calculate log of all the elements of the array.

Do let me know if there’s any query regarding Numpy by contacting me on email or LinkedIn.

So this is all for this blog folks, thanks for reading it and I hope you are taking something with you after reading this and till the next time ?…

Read my previous blog: TOP 11 MUST LEARN PYTHON LIBRARIES FOR DATA SCIENCE ASPIRANTS

Check out my other machine learning projectsdeep learning projectscomputer vision projectsNLP projectsFlask projects at machinelearningprojects.net.

Leave a Comment

Your email address will not be published.