Hi friends,
Welcome to another NumPy tutorial under Data Science & Machine Learning. In the previous post, we discussed several ways to index NumPy Arrays and Conditional Selection in NumPy Arrays. In this post, we will learn several operations that we can perform on NumPy Arrays. We will also see various methods supported by the NumPy library to deal with NumPy Arrays.
Note: All the commands discussed below are run in the Jupyter Notebook environment. See this post on Jupyter Notebook to know about it in detail.
Note: All the commands discussed below are run in the Jupyter Notebook environment. See this post on Jupyter Notebook to know about it in detail.
NumPy Array Methods
So, let's first declare a NumPy Array using the NumPy's arange() function:
- We can add/subtract a scalar to the NumPy Array:
- We can multiply/divide a scalar to the NumPy Array:
We can perform the same operations among the NumPy Arrays as well.
Notice the warning generated due to division by zero operation. However, the division was successful and the output was inf (for 1/0).
We can also perform exponentiation operation using the ** operator in Python. Here is the operation for raising each element of the NumPy Array to the power of 3:
Now, we see some useful methods supported by NumPy library for NumPy arrays:
- sqrt() - This method finds the square root of each element of a NumPy array
- max() - This returns the maximum element in a NumPy Array
- min() - Returns the minimum element of a NumPy Array
- Trigonometric functions - NumPy also supports trigonometric methods like sin(), cos() and tan()
- mean() - Returns the mean of a NumPy Array
- log() - Performs the natural logarithm of each element of a NumPy Array
Notice, there is a warning since logarithm of zero does not exist.
You can visit this link to know the list of all the functions supported over NumPy arrays by the NumPy library.
From the next post, we'll start with Pandas, another very important library for Data Science under Data Science & Machine Learning.
0 comments:
Post a Comment