Found 34488 Articles for Programming

Convert angles from radians to degrees in a NumPy array

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

68 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

Ways to check if a String in Python Contains all the same Characters

Aayush Shukla
Updated on 07-Aug-2023 21:38:26

347 Views

Python is a very commonly used programming language used for different purpose such as web development, data science, machine learning and to perform many different processes with automation. In this article we will learn about different ways to check if a string in python contains all the same characters. Different Methods to Check if a String in Python Contains All the Same Characters Set Function Set will help us to check the similarities in between the strings given as input in the program. This is a very simple method and the output will be displayed as ... Read More

Convert a NumPy array to an image

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

6K+ 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

Python - Vowel Indices in String

Aayush Shukla
Updated on 07-Aug-2023 21:34:30

221 Views

Python is a widely used programming language for different purposes such as web development, data science machine learning and to perform many different processes with automation. In this article, we'll explore how to use several Python features to extract vowel indices from a given text. Different Methods to Find Vowel Indices in a String For Loop In this method by simply checking each element in the string, we can determine if it is a vowel and record its index. We can understand it in a better way through the following syntax and example: - Example def vowel_indices_in_a_string(whole_string): ... Read More

Convert a NumPy array into a csv file

Niharika Aitam
Updated on 09-Aug-2023 09:57:05

483 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

99 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

587 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

255 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

171 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

How to Change the Background of an Image with Green Screen Background in MATLAB?

Manish Kumar Saini
Updated on 07-Aug-2023 17:30:09

211 Views

In this article, we learn how to change the green background of an image to some other background using MATLAB programming. The concept of changing a green screen background to another background involves the use of a technology called “chroma key”. This technology detects the absolute green color in the image and omits it from the image. Then, we can apply another image or color as the background to the image. Algorithm The step−by−step process of changing the green screen background of an image with another background in MATLAB is explained below: Step (1) − Read the input image with ... Read More

Advertisements