Found 1204 Articles for Numpy

Convert angles from radians to degrees in a NumPy array

Niharika Aitam
Updated on 09-Aug-2023 10:00:33

57 Views

Degrees and Radians are the two units of measurement for the angles. Degrees are the most commonly used unit of measurement for the angles. It is denoted by theta(Ø). There are 360 degrees in circle and each degree is divided into 60 minutes and each minute is further divided into 60 seconds. Mathematically the radians converted into degrees by multiplying the radian with 180/pi. The Radians are the natural unit of measurement of the angles in physics, mathematics and engineering. Simply we can define the radians as the length of an arc of the circle to the radius of ... Read More

Convert a NumPy array to an image

Niharika Aitam
Updated on 09-Aug-2023 09:59:16

4K+ 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
Updated on 09-Aug-2023 09:57:05

345 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

Convert a Python array into a Numpy array

Niharika Aitam
Updated on 09-Aug-2023 09:55:07

75 Views

Array is one of the data structures which allows us to store the same data type elements in a contiguous block of memory. Arrays can be in one dimension or two dimension or three dimension up to 32 dimensions. In python, there are different ways to create arrays. One way is by using the built-in module array which allows us to create the array with different data types like integers and floats. The other way is by using the Numpy library, which provides most powerful and flexible functions to implement the arrays. Creating array using array module The built in ... Read More

Compute the weighted average of a given NumPy array

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

452 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

179 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

138 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

44 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

157 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

59 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

Advertisements