Posts

Showing posts with the label numpy array

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

Create array in tensorflow | Data Science tutorial | codin india

Image
 Hello! Welcome back to our tutorial. Today we will learn how to create array in tensorflow. What is tensorflow? Tensorflow is open source platform for machine learning. It has comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-art in ML and developing easily build and deploy ML powered applications.   How to import Tensorflow?    import tensorflow as tf import numpy as np  How to create array in tensorflow? We have 2 methods to create array in tensorflow:-  Using tensorflow inbuilt function Using numpy Let us understand it one by one. 1. Using Tensorflow's inbuilt function  We can create array in tensorflow using  tensorflow's inbuilt function i.e. constant arr  = tf.constant([1,2,3,4,5]) Let us understand by code:- What is constant? constant is useful for asserting that the value can be embedded that way. If the argument dtype is not specified, then the type is inferred from the type of value 2. Using Nump

Array Concatenation and methods of stack | numpy array tutorial | Codin india

Image
    Numpy is Python module that is used for array creation, modification and creating sub arrays for numpy arrays. Concatenation of arrays Concatenation or joining of two arrays in Numpy, is primarily accomplished through the routines np.concatenate, np.vstack and np.hstack. Let us see all of the one by one. Concatenate:- It will concatenate two arrays and gives the output as one array. Let us see by code:- From the above code, it is clear that np.concatenate takes two argument as input and adds the value of both array and return the output as one array. Concatenate 3 or more arrays:- we can concatenate as any array we want. Let us talk, where the case of 3 arrays, we will concatenate all the 3 arrays Concatenation of same array:- We can also concatenate same array together. Like we can concatenate x + x. Let's see the Code:- NOTE:-   point here to be noted that, the arguments should be passed in [] brackets only.  np.concatenate([x, y]) 2-D or multidimensional Array Concatenation: