July 2023

  • WHAT IS BINOMIAL DITRIBUTION IN PYTHON?

    Binomial Distribution describes the outcome of binary scenarios, e.g. toss of a coin, it will either be head or tails. Binomial Distribution is a Discrete Distribution. binomial() method in NumPy Python has three parameters: n – number of trials. p – probability of occurence of each trial (e.g. for toss of a coin 0.5 each).…

  • WHAT IS NORMAL OR GAUSSIAN DISTRIBUTION IN PYTHON?

    NORMAL OR GAUSSIAN DISTRIBUTION The random.normal() method is used to get a Normal Data Distribution. It has three parameters- loc – (Mean) where the peak of the bell exists. scale – (Standard Deviation) how flat the graph distribution should be. size – The shape of the returned array. Output- Explanation– random.normal(size=(2, 2)) – It will…

  • WHAT IS SEABORN IN PYTHON?

    Seaborn is an open-source Python library built on top of matplotlib. It is used for data visualization and exploratory data analysis. Seaborn is commonly used for data science and machine learning task. How to install Seaborn? We can install Seaborn using following command, python and pip installation on the machine is pre required. Importing Matplotlib…

  • HOW TO GENERATE RANDOM PERMUTATIONS OF PYTHON NUMPY ARRAY?

    Random Permutations Random Permutations means arrangement of the elements of array in different ways. The shuffle() and permutation() methods from random module of python’s numpy library is used to generate permutations of arrays. Shuffling Arrays Shuffling means changing arrangement of elements in the array itself. The shuffle() method is used to shuffle the elements of…

  • HOW TO USE DATA DISTRIBUTION IN PYTHON NUMPY?

    What is Data Distribution? Data Distribution is a list of all possible values, and how often each value occurs or their relative frequency. The methods available in random module of numpy library is used to get the randomly generated data distributions. Random Distribution A random distribution is a set of random numbers that follow a…

  • HOW TO GENERATE RANDOM NUMBERS USING PYTHON NUMPY?

    Generating random no.- The random module of numpy library is used to generate random nos. in python. Output- 5 It will generate a random integer from 0 to 10. Generating random float- The rand() method returns a random float between 0 and 1. Output- Generating random array- The randint() method takes a size parameter where…

  • HOW TO FILTER PYTHON NUMPY ARRAYS?

    We can filter an array using boolean index list, which is a list of booleans corresponding to indexes in the array. If the value at an index is True that element is contained in the filtered array, if the value at that index is False that element is excluded from the filtered array. Output- The…

  • HOW TO SORT PYTHON NUMPY ARRAYS?

    The sort() method is used to sort the array in an order, it returns a copy of the array, leaving the original array unchanged. Output-

  • HOW TO USE SEARCH IN NUMPY ARRAYS?

    The where() method is used to search the certain value in an array and return the indexes that get a match. Output- Search Sorted- The searchsorted() method performs a binary search in the sorted array, and returns the index where the specified value would be inserted to maintain the search order. Output- Explanation- np.searchsorted(arr, 3)…

  • HOW TO SPLIT PYTHON NUMPY ARRAY?

    Splitting Python NumPy Arrays The array_split() method is used for splitting arrays, by passing it the array we want to split and the number of splits. It will returns the list of arrays. If the array has less elements than required as per split specified, it will adjust from the end accordingly. We can also…

  • HOW TO JOIN PYTHON NUMPY ARRAYS?

    The concatenate() method is used to join the numpy arrays by passing sequence of arrays along with the axis and in case if axis is not passed it will consider it as 0. Output- Joining Arrays Using Stack Functions- The stack() method is used for joining two arrays and stacking is same as concatenation, the…

  • HOW TO ITERATE NUMPY ARRAYS?

    We can iterate on the elements of NumPy Arrays by using for loops. Iterating 1-D Array- Output- Iterating 2-D Arrays– Output- Iterating on each element of the 2-D array Output- Iterating 3-D Arrays- Output– To iterate on each scalar value of 3D array, we need to iterate in each dimension- Output- Iterating Arrays Using nditer()…

  • HOW TO RESHAPE ARRAY IN PYTHON NUMPY?

    The method reshape() is used to reshape the python numpy array. Reshaping Python Numpy Array means changing the shape of an array by adding or removing dimensions or changing number of elements in each dimension. Output- Explanation- arr.reshape(4, 2)- Convert the 1-D array- arr with 8 elements into a 2-D array. The outermost dimension will…

  • HOW TO GET THE SHAPE OF AN ARRAY IN PYTHON NUMPY?

    WHAT IS SHAPE OF AN ARRAY IN PYTHON NUMPY? The shape of an array is the number of elements in each dimension. Getting the Shape of an Array- shape attribute of python numpy returns a tuple with each index having the number of corresponding elements. Output- Explanation- The above example returns shape tuple – (2,…

  • WHAT IS THE DIFFERENCE BETWEEN COPY AND VIEW OF AN ARRAY IN PYTHON NUMPY?

    The main difference between a copy and a view of an array is that the copy is a new array and it owns the data, and the view is just a view of the original array and it doesn’t own the data. The copy owns the data where as the view does not own the…

  • HOW TO CREATE VIEW OF PYTHON NUMPY ARRAY?

    View is just a view of the original array, it can be created by view() method and main property of view is that the view does not own the data and any changes made to the view will affect the original array, and any changes made to the original array will affect the view. Output-

  • HOW TO CREATE COPY OF ARRAY IN PYTHON NUMPY?

    Creating copy of an array in Python NumPy- We can create copy of an array in Python NumPy by using copy() method. The copy owns the data and any changes made to the copy will not affect original array, and any changes made to the original array will not affect the copy. Output- Explanation- x…

  • WHAT IS THE DATA TYPE OF ARRAY IN PYTHON NUMPY?

    Python NumPy Data Types Numpy data types and the characters used to represent them are listed below- i – integerb – booleanu – unsigned integerf – floatc – complex floatm – timedeltaM – datetimeO – objectS – stringU – unicode stringV – fixed chunk of memory for other type ( void ) How to check…

  • WHAT IS ARRAY SLICING IN PYTHON NUMPY?

    Accessing elements of an array from one given index to another given index is known as slicing in python. Instead of passing index, we pass slice with step – [start:end:step] If we don’t pass start its considered 0 If we don’t pass end its considered length of array in that dimension If we don’t pass…

  • HOW TO ACCESS ARRAY ELEMENTS IN PYTHON NUMPY?

    Numpy Array Indexing or Accessing Array Elements We can access an array element by referring to its index number. Array indexing is the same as accessing an array element. The indexes in NumPy arrays start with 0. Example- Following example shows that how to access the first element of given array arr. First element of…