Posts

Showing posts with the label numpy tutorial

Compare two arrays in numpy | Data Science tutorial | codin india

Image
   Hey Friends! In today's post, we will learn how to compare two arrays in Numpy. For comparison in Numpy, we have two methods. == comparison operator or NumPy comparison operator Let us understand both methods one by one. 1. Using == operator We can do element to element-wise comparison using == operator.  Syntax:-   array1 == array2 Let us undestand it by Code:- Explanation:- In the above code, we created two arrays and then compare both of them with == operator. imported NumPy as np arr1 and arr2 are arrays print the result of the comparison OutPut Explanation :- It will compare both arrays element-wise i.e one element from one array to one element of another element and print the output. In the above example, it compared both arrays and gives output element-wise. 2. Using comparison operator We can compare array using a comparison operator also. It will also compare arrays element-wise and provide output as True or False.  We have standard Python comparison operators to compar

Slicing of Numpy Arrays | Data Science tutorial| codin india

Image
Hello Friends, in this tutorial we will learn about what is indexing and slicing. Let us see one by one. What is indexing? Indexing is a term of defining something orderly. It is used when we want something in a specific range. Suppose you have multiple copies of the same item and you have to remember or recognize every item then you will give every item a unique name or number. That exactly what indexing is. In   Numpy Arrays   indexing start from 0 like   List   in   Python. EX:- myarr = np.array([101,102,103,104,105]) In the given example, the indexing start from zero. If I call the 3rd item from   myarr   array it will give me 104 from the array. What is slicing of array? Slicing of arrays indicates that calling the specific value or range of value from Array. Slicing of Array is almost the same as Slicing of string. We can fetch a specific value from the array, range of values from arrays, call values in reverse order and call value by jumping one or more element. You can slice ac