Found 27104 Articles for Server Side Programming

Compute the weighted average of a given NumPy array

Niharika Aitam
Updated on 09-Aug-2023 09:53:37

561 Views

Weighted average is a type of average in which each array element will be multiplied by a weight factor before calculating the mean of the data elements. The weight of each data point determines its contribution to all its overall average. Calculating weighted average This is used to calculate the average price of a stock in a portfolio value. The mathematical formula of the weighted average is given as follows. weighted_average = (w1 * x1 + w2 * x2 + ... + wn * xn) / (w1 + w2 + ... + wn) Where, x1, x2, ….., ... Read More

Compute the Reciprocal for all elements in a NumPy array

Niharika Aitam
Updated on 09-Aug-2023 09:50:48

243 Views

The reciprocal of a number is defined as the multiplicative inverse of that number, when we have a non-zero number ‘a’ then the reciprocal of ‘a’ will be ‘b’, Hence, a * b = 1. In other words, reciprocal of ‘a’ is given as ‘1/a’. The reciprocal() function We can calculate the reciprocal of an array using the reciprocal() function of the Numpy library. This function accepts an array as a parameter and returns the reciprocal of the elements of the given array. The within the same shape and size of the original array. Syntax Following is the syntax for ... Read More

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

Niharika Aitam
Updated on 07-Aug-2023 19:35:47

169 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 median of the flattened NumPy array

Niharika Aitam
Updated on 07-Aug-2023 18:17:02

61 Views

MedianThe median is the statistical measure for the central tendency that represents the middle value of the sorted list of values. In other words, we can say that the median is the value which separates the upper half of the dataset from the lower half of the dataset. The mathematical formula for calculating the median is as follows when the total number of elements is odd. Median = (n+1)/2 Where, n is the last element from the given set. Flattened array Flattening is a process of reducing the dimensionality of an array. flattened array is a 1-d ... Read More

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

Niharika Aitam
Updated on 07-Aug-2023 18:08:11

208 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
Updated on 07-Aug-2023 18:02:58

69 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 inner product of vectors for-D arrays using NumPy in Python

Niharika Aitam
Updated on 07-Aug-2023 17:44:42

103 Views

Inner product is one of the most important operations in the linear algebra mathematical operations, which takes two vectors as input and gives the scalar value as the output. It is also known as the Dot product or the scalar product. The inner product of the two vectors is given as follows. a . b = ||a|| ||b|| cos(Ø) Where, ||a|| and ||b|| are the magnitudes of the vectors a and b respectively Ø is the angle between the vectors a and b a . b is the dot product of a and b Calculating Inner ... Read More

Compute the histogram of nums against the bins using NumPy

Niharika Aitam
Updated on 07-Aug-2023 17:41:41

72 Views

In python, for creating histograms we have the numpy, matplotlib and seaborn libraries. In Numpy, we have the function namely histogram() to work with the histogram data. The input argument for the histogram() function is the nums and bins. The nums are used to create the numerical data. Before proceeding with the examples first of all let us understand what is histogram. What is histogram Histogram is the graphical representation of the dataset distribution. It represents the data in the form of series of bars, where the range of data values represented by each bar and height of the bar ... Read More

Compute the histogram of a set of data using NumPy in Python

Niharika Aitam
Updated on 07-Aug-2023 17:39:36

107 Views

A Histogram is the graphical representation of the dataset distribution. It represents the data in the form of series of bars, where the range of data values represented by each bar and height of the bar represents the frequency of the data values defined within the range. These are mainly used to represent the distribution of the numerical data like grades in a class, distribution of the population or distribution of the incomes of the employees etc. In histogram, x-axis represents the range of data values, divided into intervals and the y-axis represents the frequency of the range of data ... Read More

Compute the factor of a given array by Singular Value Decomposition using NumPy

Niharika Aitam
Updated on 07-Aug-2023 17:36:42

99 Views

Singular Value Decomposition (SVD) is the matrix factorization technique which divides the matrix into three parts namely left singular matrix, a diagonal singular matrix and right singular matrix. SVD is powerful tool used in linear algebra and it has number of applications in data analysis, machine Learning and signal processing. This is mainly used to compute the rank of the matrix, as well as to perform the linear equations and performing the image compression and many more operations. Calculating Singular Value Decomposition If we compose a real or complex matrix A with the size m x n, then ... Read More

Advertisements