Found 1204 Articles for Numpy

Get the Outer product of two arrays in Python

AmitDiwan
Updated on 25-Feb-2022 07:08:29

2K+ Views

To get the Outer product of two arrays, use the numpy.outer() method in Python. The 1st parameter a is the first input vector. Input is flattened if not already 1-dimensional. The 2nd parameter b is the second input vector. Input is flattened if not already 1-dimensional. The 3rd parameter out is a location where the result is stored.Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product [1] is −[[a0*b0 a0*b1 ... a0*bN ] [a1*b0 . [ ... . [aM*b0 aM*bN ]]StepsAt first, import the required libraries-import numpy as npCreating two ... Read More

Get the Inner product of an array and a scalar in Python

AmitDiwan
Updated on 25-Feb-2022 07:06:22

163 Views

To get the Inner product of an array and a scalar, use the numpy.inner() method in Python. Ordinary inner product of vectors for 1-D arrays, in higher dimensions a sum product over the last axes. The parameters are 1 and b, two vectors. If a and b are nonscalar, their last dimensions must match.StepsAt first, import the required libraries-import numpy as npCreate an array using numpy.eye(). This method returns a 2-D array with ones on the diagonal and zeros elsewhere −arr = np.eye(5)The val is the scalar −val = 2Check the datatype −print("Datatype of Array...", arr.dtype) Check the Dimension −print("Dimensions ... Read More

Compute the multiplicative inverse of a matrix in Python

AmitDiwan
Updated on 25-Feb-2022 07:02:16

1K+ Views

To compute the (multiplicative) inverse of a matrix, use the numpy.linalg.inv() method in Python. Given a square matrix a, return the matrix ainv satisfying dot(a, ainv) = dot(ainv, a) = eye(a.shape[0]). The method returns (Multiplicative) inverse of the matrix a. The 1st parameter, a is a Matrix to be inverted.StepsAt first, import the required libraries-import numpy as np from numpy.linalg import invCreate an array −arr = np.array([[ 5, 10], [ 15, 20 ]])Display the array −print("Our Array...", arr)Check the Dimensions −print("Dimensions of our Array...", arr.ndim)Get the Datatype −print("Datatype of our Array object...", arr.dtype)Get the Shape −print("Shape of our Array object...", ... Read More

Return the lowest index in the string where substring is found in a range using Python index()

AmitDiwan
Updated on 25-Feb-2022 06:42:28

98 Views

Return the lowest index in the string where substring sub is found using the numpy.char.index() method in Python Numpy. The method returns the output array of ints. Raises ValueError if sub is not found. The first parameter is the input array. The second parameter is the substring to be searched. The third and fourth parameter are optional arguments, wherein start and end are interpreted as in slice notation.StepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['KATIE', 'KATE', 'CRATE']) Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions ... Read More

Return the lowest index in the string where substring is found using Python index()

AmitDiwan
Updated on 25-Feb-2022 06:40:31

224 Views

Return the lowest index in the string where substring sub is found using the numpy.char.index() method in Python Numpy. The method returns the output array of ints. Raises ValueError if sub is not found. The first parameter is the input array. The second parameter is the substring to be searched.StepsAt first, import the required library −import numpy as npCreate a One-Dimensional array of strings −arr = np.array(['KATIE', 'KATE']) Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", arr.ndim)Get the shape of the Array −print("Our Array Shape...", arr.shape) Get the number of ... Read More

Compute the inverse Hyperbolic cosine in Python

AmitDiwan
Updated on 25-Feb-2022 06:37:13

339 Views

The arccosh() is a multivalued function: for each x there are infinitely many numbers z such that cosh(z) = x. The convention is to return the z whose imaginary part lies in [-pi, pi] and the real part in [0, inf]. For real-valued input data types, arccosh always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, arccosh is a complex analytical function that has a branch cut [-inf, 1] and is continuous from above on it.To compute the ... Read More

Compute the inverse Hyperbolic sine of array elements in Python

AmitDiwan
Updated on 25-Feb-2022 06:35:03

140 Views

The arcsinh is a multivalued function: for each x there are infinitely many numbers z such that sinh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2]. For real-valued input data types, arcsinh always returns real output. For each value that cannot be expressed as a real number or infinity, it returns nan and sets the invalid floating point error flag.For complex-valued input, arccos is a complex analytical function that has branch cuts [1j, infj] and [- 1j, -infj] and is continuous from the right on the former and from the left on ... Read More

Compute the inverse Hyperbolic sine in Python

AmitDiwan
Updated on 25-Feb-2022 06:31:15

696 Views

The arcsinh is a multivalued function: for each x there are infinitely many numbers z such that sinh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2]. For real-valued input data types, arcsinh always returns real output. For each value that cannot be expressed as a real number or infinity, it returns nan and sets the invalid floating point error flag. For complex-valued input, arccos is a complex analytical function that has branch cuts [1j, infj] and [-1j, -infj] and is continuous from the right on the former and from the left on ... Read More

Compute the Hyperbolic cosine in Python

AmitDiwan
Updated on 25-Feb-2022 06:29:25

252 Views

To compute the Hyperbolic cosine, use the numpy.cosh() method in Python Numpy. The method is equivalent to 1/2 * (np.exp(x) + np.exp(-x)) and np.cos(1j*x). Returns the corresponding hyperbolic cosine values. This is a scalar if x is a scalar. The 1st parameter, x is input array. The 2nd and 3rd parameters are optional.The 2nd parameter is an ndarray, A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. The 3rd parameter is the condition is broadcast over the input. At ... Read More

Compute the Hyperbolic sine of the array elements in Python

AmitDiwan
Updated on 25-Feb-2022 06:26:39

159 Views

To compute the Hyperbolic sine of the array elements, use the numpy.sinh() method in Python Numpy. The method is equivalent to 1/2 * (np.exp(x) - np.exp(-x)) or -1j * np.sin(1j*x). Returns the corresponding hyperbolic sine values. This is a scalar if x is a scalar. The 1st parameter, x is input array. The 2nd and 3rd parameters are optional.The 2nd parameter is an ndarray, A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.The 3rd parameter is the condition is ... Read More

Advertisements