NumPy is a powerful #python library that helps us compute operations on primarily numbers, faster. It is an important tool for data science. 💪
Here are 5 powerful #NumPy functions that will help you in your projects!
#Thread ☕
#MachineLearning #datascience #AI
Let's go! ⬇️
First let’s see the advantages of using NumPy : 📈
1️⃣ Uses low memory to store data.
2️⃣ We can create n-dimensional arrays.
3️⃣ Operations like indexing, broadcasting, slicing and matrix multiplication.
4️⃣ Finding elements in the array is easy.
5️⃣ Good documentation.
Function 1 : np.sort()
This returns a sorted copy of the array. The original array is not changed.
The arguments the function normally takes are -
1. The Array to be sorted.
2. Axis along which to sort.
3. The method/ algorithm used for sorting as “kind = ”.
Function 2 : np.count_nonzero()
Used to count number of nonzero elements in an array.
The arguments taken are -
1. Array from which the nonzero values are to be found.
2. Axis. (optional)
Returns the number of nonzero elements in an array OR along an axis.
Function 3 : numpy.where()
does one operation on those that satisfy the condition and another on those that do not satisfy the condition.
Arguments taken are -
1. Condition.
2. x — do x if condition True.
3. y — do y if condition False.
Returns an array with x and y executed.
Function 4 : numpy.compress()
Returns a slice of values that satisfy a conditional array. This function takes following arguments -
1. A 1D conditional array.
2. Array on which the compression is done.
3. Axis along which the compression is done.
Function 5 - numpy.trace()
Really cool function that returns sum of values along the diagonal of an array.
Arguments taken are -
1. An array.
2. Offset from diagonal.
3. Axis.
Returns an array with the sum along all the diagonals in the array.
We had a good look under the hood of NumPy documentation which is almost impossible to know 100%.
There are useful functions that can do a job efficiently and with less code. That’s the power of the NumPy library.
For more informative resources, follow @ml_india_! 🤓
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.