Python generic function is calculated by an array

An arithmetic array

Array operation can be addition, subtraction, while these may be arithmetic operators for any combination effect has been reached.

>>> x=np.arange(5)
>>> x
array([0, 1, 2, 3, 4])
>>> x=5
>>> x=np.arange(5)
>>> x+5
array([5, 6, 7, 8, 9])
>>> x-5
array([-5, -4, -3, -2, -1])
>>> x*2
array([0, 2, 4, 6, 8])
>>> x/2
array([0. , 0.5, 1. , 1.5, 2. ])
>>> x//2
array([0, 0, 1, 1, 2], dtype=int32)

Two absolute value operation

There are three methods, the first method is the direct use abs NumPy library function is not calculated, the second and third methods are carried out using a calculation function and the absolute abs numpy library functions. As follows:

>>> x=np.array([1,2,3,-4,-5,-6])
>>> x
array([ 1,  2,  3, -4, -5, -6])
>>> abs(x)
array([1, 2, 3, 4, 5, 6])
>>> np.abs(x)
array([1, 2, 3, 4, 5, 6])
>>> np.absolute(x)
array([1, 2, 3, 4, 5, 6])

III. Trigonometric operations

First, a definition of a np among the array of objects, and then calculates:

>>> a
array([0.        , 1.57079633, 3.14159265])
>>> np.sin(a)
array([0.0000000e+00, 1.0000000e+00, 1.2246468e-16])
>>> np.cos(a)
array([ 1.000000e+00,  6.123234e-17, -1.000000e+00])
>>> np.tan(a)
array([ 0.00000000e+00,  1.63312394e+16, -1.22464680e-16])

IV. Exponential and the logarithm of the operation

Index calculation:

>>> x=[1,2,3]
>>> x
[1, 2, 3]
>>> np.exp(x)
array([ 2.71828183,  7.3890561 , 20.08553692])
>>> np.exp2(x)
array([2., 4., 8.])
np.power(3,x)
array([ 3,  9, 27], dtype=int32)

Operations on numbers:

>>> np.log(x)
array([0.        , 0.69314718, 1.09861229])
>>> np.log2(x)
array([0.       , 1.       , 1.5849625])
>>> x
[1, 2, 3]
>>> np.log10(x)
array([0.        , 0.30103   , 0.47712125])

 

 

Guess you like

Origin www.cnblogs.com/geeksongs/p/11015807.html