Follow me on LinkedIn, GitHub, YouTube
NumPy tricks with coding examples and outputs
-Anupam Shrivastava
NumPy stands for Numerical Python, and it is a Python library used for working with arrays. It is particularly useful for scientific computing tasks, such as linear algebra, Fourier transform, and random number capabilities, and is widely used in the data science and machine learning communities. NumPy provides efficient and convenient operations for numerical arrays, and it also offers built-in functions for mathematical operations on arrays, such as trigonometric, statistical, and algebraic routines.
Here are some NumPy tricks which are useful for Python coding:
1. Creating a numpy array with a specific shape and data type using np.zeros() or np.ones()
Output:
2. Reshaping a numpy array using np.reshape():
You can use the numpy.reshape function to change the shape of an array. For example:
Output:
3. Flattening a numpy array using np.flatten():
Output:
4. Transposing a numpy array using np.transpose():
You can use the numpy.transpose function to switch the rows and columns of a multidimensional array. For example:
Output:
5. Finding the maximum or minimum value in a numpy array using np.max() or np.min():
Output:
6. Generate random numbers with numpy.random.rand
Output:
These are just a few examples of the many tricks you can use with Numpy. With practice and experimentation, you can become proficient in using Numpy to solve a wide range of numerical problems.
These tricks can help you save time and simplify your data analysis process in NumPy.
I trust that you have gained valuable insights from my blog.
Wishing you a fulfilling learning journey!
Thank you for reading.
If you find my blogs informative and useful, please consider following me on
and YouTube (https://bit.ly/3Jd0gss). [ Like, Share, & Subscribe ]
By following you'll receive notifications directly whenever I publish articles/post/videos on Python, Data Science, Machine Learning, SQL and more.
Comments
Post a Comment