Found 33676 Articles for Programming

Clip (limit) the values in a Numpy array

AmitDiwan
Updated on 22-Feb-2022 09:41:01

951 Views

To clip (limit) the values in an array, use the np.ma.clip() method in Python Numpy. Given an interval, values outside the interval are clipped to the interval edges. For example, if an interval of [0, 1] is specified, values smaller than 0 become 0, and values larger than 1 become 1. Equivalent to but faster than np.minimum(a_max, np.maximum(a, a_min)).The out is where the results will be placed in this array. It may be the input array for in-place clipping. out must be of the right shape to hold the output. Its type is preserved.The function returns an array with the ... Read More

Java Program to Find Factorial of a Number Using Recursion

Manisha Chand
Updated on 18-Jun-2025 17:05:44

909 Views

In this article, we will understand how to find the factorial of a number using recursion in Java. The factorial of a positive number is the product of the number itself and all descending positive integers up to "n". The factorial of a negative number does not exist, and the factorial of 0 is 1. The factorial of a positive number is - factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n Factorial Using a Recursive Function A recursive function is a function that calls itself multiple times until a particular condition is satisfied. ... Read More

Java Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Shriansh Kumar
Updated on 19-Jun-2025 10:12:31

1K+ Views

The given task is to write a Java program to check if an integer can be expressed as the sum of two prime numbers. A number is said to be a prime if it has only two factors, which are 1 and itself, and cannot be divided by any other number. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number; all other prime numbers are odd numbers. Example Scenario Let's understand the problem with an example. The possible solution is 43 = 2 + 41. Here, 2 and ... Read More

Generate a Vandermonde matrix and set the number of columns in the output in Numpy

AmitDiwan
Updated on 22-Feb-2022 09:37:20

285 Views

To generate a Vandermonde matrix, use the np.ma.vander() method in Python Numpy. Set the number of columns in the output using the N parameter. If N is not specified, a square array is returned (N = len(x)).The columns of the output matrix are powers of the input vector. The order of the powers is determined by the increasing boolean argument. Specifically, when increasing is False, the i-th output column is the input vector raised element-wise to the power of N - i - 1. Such a matrix with a geometric progression in each row is named for Alexandre- Theophile Vandermonde.StepsAt ... Read More

Java Program to Make a Simple Calculator Using switch...case

AmitDiwan
Updated on 22-Feb-2022 09:22:12

4K+ Views

In this article, we will understand how to construct a simple calculator using switch-case. The switch statement evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.Following are the arithmetic operations we are going to perform.AdditionSubtractionMultiplicationDivisionFloor DivisionModuloBelow is a demonstration of the same −InputSuppose our input is −The two inputs: 40.0 and 12.0 Operator:%OutputThe desired output would be −The result is 40.0 % 12.0 = 4.0AlgorithmStep 1 - START Step 2 - Declare three values namely my_input_1, my_input_2 and my_result and declare a character value namely operator. Step 3 - Read the required ... Read More

Generate a Vandermonde matrix in Numpy

AmitDiwan
Updated on 22-Feb-2022 08:13:21

221 Views

To generate a Vandermonde matrix, use the np.ma.vander() method in Python Numpy. A Vandermonde matrix, named after Alexandre-Théophile Vandermonde, is a matrix with the terms of a geometric progression in each row.The columns of the output matrix are powers of the input vector. The order of the powers is determined by the increasing boolean argument. Specifically, when increasing is False, the i-th output column is the input vector raised element-wise to the power of N - i - 1. Such a matrix with a geometric progression in each row is named for Alexandre- Theophile Vandermonde.StepsAt first, import the required library ... Read More

Java Program to Display Factors of a Number

Manisha Chand
Updated on 09-Jun-2025 12:39:33

7K+ Views

In this article, we will understand how to display the factors of a number. Factors are numbers that divide the original number without leaving a remainder. For example, 1, 2, 3, 4, 6, and 12 are factors of 12. If a and b are factors of a number, then a x b is also a factor of the number. If we multiply 3 and 5, we get 15. We say that 3 and 5 are factors of 15. The largest factor of any number is the number itself, and the smallest factor is 1. 1 ... Read More

Return the outer product of two masked One-Dimensional Numpy arrays

AmitDiwan
Updated on 22-Feb-2022 08:07:47

167 Views

To return the outer product of two masked 1D arrays, use the ma.outer() method in Python Numpy. The first parameter is the input vector. Input is flattened if not already 1-dimensional. The second parameter is the second input vector. Input is flattened if not already 1-dimensional.A masked array is the combination of a standard numpy.ndarray and a mask. A mask is either nomask, indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.StepsAt first, import the required library −import ... Read More

Return the outer product of two masked arrays in Numpy

AmitDiwan
Updated on 22-Feb-2022 07:58:48

151 Views

To return the outer product of two masked arrays, use the ma.outer() method in Python Numpy. The first parameter is the input vector. Input is flattened if not already 1-dimensional. The second parameter is the second input vector. Input is flattened if not already 1-dimensional.A masked array is the combination of a standard numpy.ndarray and a mask. A mask is either nomask, indicating that no value of the associated array is invalid, or an array of booleans that determines for each element of the associated array whether the value is valid or not.StepsAt first, import the required library −import numpy ... Read More

Java program to display prime numbers between intervals using function

Alshifa Hasnain
Updated on 24-Dec-2024 17:46:58

580 Views

In this article, we will understand how to display prime numbers between intervals using a function in Java. We will be using two approaches: one with user input and the other with predefined input. Prime numbers The prime numbers are special numbers that have only two factors 1 and itself and cannot be divided by any other number. A number is a prime number if its only factors are 1 and itself. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is ... Read More

Advertisements