SoFunction
Updated on 2025-03-03

Detailed explanation of NumPy hyperbolic function and set operation

NumPy hyperbolic function

NumPy providessinh()cosh()andtanh()etc ufunc, which accept radian values ​​and generate corresponding hyperbolic sine, hyperbolic cosine and hyperbolic tangent values.

Example:

import numpy as np

x = (/2)

print(x)

Example

Find the arrayarrHyperbolic cosine values ​​for all values ​​in:

import numpy as np

arr = ([/2, /3, /4, /5])

x = (arr)

print(x)

Find angles

Find angles from hyperbolic sine, hyperbolic cosine, hyperbolic tangent values. For example, the inverse functions of sinh, cosh, and tanh (arcsinh, arccosh, arctanh).

NumPy providesarcsinh()arccosh()andarctanh()etc. ufunc, which give the radian values ​​of the corresponding sinh, cosh, and tanh values.

Example

turn up1.0Angle:

import numpy as np

x = (1.0)

print(x)

Angle of each value in the array

Example

Find all in the arraytanhValue angle:

import numpy as np

arr = ([0.1, 0.2, 0.5])

x = (arr)

print(x)

NumPy collection operation

What is a collection

In mathematics, a set is a collection of unique elements.

Sets are used to perform frequent intersection, union and difference operations.

Create collections in NumPy

We can use NumPy'sunique()Methods find unique elements from any array. For example, create an array of collections, but remember that the array of collections should be just one-dimensional arrays.

Example Convert the following array containing duplicate elements to a collection:

import numpy as np

arr = ([1, 1, 1, 2, 3, 4, 5, 5, 6, 7])

x = (arr)

print(x)

Find and assemble

To find the unique value of two arrays, useunion1d()method.

Example

Find the union of the following two collection arrays:

import numpy as np

arr1 = ([1, 2, 3, 4])
arr2 = ([3, 4, 5, 6])

newarr = np.union1d(arr1, arr2)

print(newarr)

Find intersection

To find values ​​that exist only in both arrays, useintersect1d()method.

Example

Find the intersection of the following two collection arrays:

import numpy as np

arr1 = ([1, 2, 3, 4])
arr2 = ([3, 4, 5, 6])

newarr = np.intersect1d(arr1, arr2, assume_unique=True)

print(newarr)

Notice:intersect1d()Method accepts an optional parameterassume_unique, if set to True, it can speed up the calculation. It should always be set to True when processing a collection.

Find the difference set

To find a value that exists in the first set but does not exist in the second set, usesetdiff1d()method.

Example

Find the difference set of set1 that does not exist in set2:

import numpy as np

set1 = ([1, 2, 3, 4])
set2 = ([3, 4, 5, 6])

newarr = np.setdiff1d(set1, set2, assume_unique=True)

print(newarr)

Notice:setdiff1d()Method accepts an optional parameterassume_unique, if set to True, it can speed up the calculation. It should always be set to True when processing a collection.

Find symmetry difference

To find a value that does not exist in both collections, usesetxor1d()method.

Example

Find the symmetry difference between set1 and set2:

import numpy as np

set1 = ([1, 2, 3, 4])
set2 = ([3, 4, 5, 6])

newarr = np.setxor1d(set1, set2, assume_unique=True)

print(newarr)

Notice:setxor1d()Method accepts an optional parameterassume_unique, if set to True, it can speed up the calculation. It should always be set to True when processing a collection.

at last

This is the end of this article about the detailed explanation of NumPy hyperbolic functions and set operations. For more related contents of NumPy hyperbolic functions and sets, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!