Numpy Articles

Page 3 of 81

How to choose elements from the list with different probability using NumPy?

Niharika Aitam
Niharika Aitam
Updated on 09-Aug-2023 1K+ Views

There are multiple ways to choose elements from the list with the different probability using the numpy library. In python, NumPy library provides a module named random, which has several functions such as choice(), multinomial() etc., which are used to choose elements from an array with different probabilities. The sum of all probability values defined in the list should be equal to 1. Let’s see each way one by one. Using the random.choice() function The random module provides the function choice(), which is used to calculate a random sample from the given 1-d array with the specified probability distribution. ...

Read More

How to check whether the element of a given NumPy array is non-zero?

Niharika Aitam
Niharika Aitam
Updated on 09-Aug-2023 335 Views

There are multiple ways to check whether the element of a given Numpy array is Non-zero. Here are few common ways that we can apply. Using Boolean indexing Boolean Indexing is a technique in Numpy library, that allows for the selection of specific elements from the array based on the Boolean condition. This creates a Boolean mask containing True or False values, which have the same shape and size as per the Boolean condition. Example Following example how to use Boolean indexing to check whether the element of a given numpy array is non-zero. import numpy as np arr = ...

Read More

How to check whether specified values are present in NumPy array?

Niharika Aitam
Niharika Aitam
Updated on 09-Aug-2023 9K+ Views

We have different modules and functions available in python language to check whether specified values are present in the given Numpy array. Numpy is abbreviated as Numerical Python, which is a python library used to perform the mathematical, statistical and scientific calculations. The result of the numpy array is returned in the format of array. The arrays can be created in one dimension, two dimension and so on up to 32 dimensions. The Numpy library provides a number of modules and functions which helps us to perform scientific calculations and mathematical calculations. Let’s see each way one by one to ...

Read More

Convert a NumPy array to an image

Niharika Aitam
Niharika Aitam
Updated on 09-Aug-2023 10K+ Views

The array created using the Numpy library can be converted into an image using the PIL or opencv libraries in python programming language. Let’s see about each library one by one. Python Image Library PIL is abbreviated as Python Image Library, which is an image processing libraries in python. It is a light weight and easy to use library to perform the image processing tasks like reading, writing, resizing and cropping the images. This library performs all the basic image processing tasks but don’t have any advanced features required for computer vision applications. We have a function in ...

Read More

Convert a NumPy array into a csv file

Niharika Aitam
Niharika Aitam
Updated on 09-Aug-2023 1K+ Views

The Numpy is the library in the python programming language which is abbreviated as Numerical Python. It is used to do the mathematical, scientific and statistical calculations within less time. The output of the numpy functions will be an array. An array created by the numpy functions can be stored in the CSV file using a function namely, savetxt(). Numpy array into a .csv file CSV is abbreviated as Comma Separated Values. This is the file format most widely used in the Data Science. This stores the data in a tabular format where the column holds the data fields and ...

Read More

Compute the outer product of two given vectors using NumPy in Python

Niharika Aitam
Niharika Aitam
Updated on 07-Aug-2023 398 Views

The Outer product of two vectors is the matrix obtained by multiplying each element of the vector A with each element in the vector B. The outer product of the vectors a and b is given as a ⊗ b. The following is the mathematical formula for calculating the outer product.a ⊗ b = [a[0] * b, a[1] * b, ..., a[m-1] * b] Where, a, b are the vectors. denotes the element-wise multiplication of two vectors. The output of the outer product is a matrix in which i and j are the elements of the ...

Read More

Compute the mean, standard deviation, and variance of a given NumPy array

Niharika Aitam
Niharika Aitam
Updated on 07-Aug-2023 702 Views

Mean, Standard Deviation and Variance are the statistical measures which are used to describe the distribution of the given dataset data. In Numpy library, we have the functions to calculate the mean, standard deviation and variance of the arrays. Let’s see one by one in detail. Mean Mean is also known as average, which is the sum of all the elements in the array divided by the total number of elements. It is used to represent the central tendency of the data. Syntax Following is the syntax for applying the mean function on the arrays - numpy.mean(arr) ...

Read More

Compute the inverse of a matrix using inv() function of NumPy

Niharika Aitam
Niharika Aitam
Updated on 07-Aug-2023 245 Views

The inverse matrix is a matrix that gives a multiplicative identity when multiplied with its original matrix. It is denoted by A-1. The inverse matrix can be calculated for the square matrices with the n x n size. The mathematical formula given for calculating the inverse matrix is as follows. A-1 . A = A . A-1 = I Where, A is the original matrix. A-1 is the inverse of the original matrix A. I is the identity matrix. Let’s take the original matrix as A with the size 2 x 2 and elements as ...

Read More

Compute the covariance matrix of two given NumPy arrays

Niharika Aitam
Niharika Aitam
Updated on 07-Aug-2023 1K+ Views

Covariance is the measure of two variables that defines how they are related to each other. In other words, it measures the extent to which one variable is associated with the changes in the other variable. When the covariance of the variables is positive, it implies that both variables are moving in the same direction i.e. if one variable tends to increase, as a result, the value of the other variable also increases. When the covariance of the variables is negative then it represents the two variables are moving in opposite direction i.e. if one variable increases the value ...

Read More

Singular Value Decomposition

Jaisshree
Jaisshree
Updated on 07-Aug-2023 641 Views

Machine learning uses the mathematical approach of Singular value decomposition to comprehend huge and complicated data sets. In this mathematical approach, a Unique Valued matrix A is factorized into three matrices via decomposition. In terms of the components of A, the Singular value decomposition of matrix A can be written as A=UDVT. In this case, S denotes A's singular values, whereas U and V stand for A's left and right singular vectors, respectively. Mathematical Algorithm Given Matrix A find the Transpose of matrix A that is (AT). Find A*AT Find the Eigen Vector of A*AT ...

Read More
Showing 21–30 of 802 articles
« Prev 1 2 3 4 5 81 Next »
Advertisements