Numpy functions in Python

Numpy functions in Python : In the python language, the development is done and sacrifices the runtime process. There are many applications to speed up python operation. The use of Numpy function is possible if you are familiar with the functions and routines. The N-dimensional matrixes have the same type of elements and began to work with array function.
There are Numpy functions as,

  1. ndarray.ndim:-This will refer to the number if axes of the current array.
  2. Ndarray.size:-count the number of elements which make array and will be equal to the product of the individual element.
  3. Ndarray.shape:-It defines the dimension of array and uses the tuples to indicate the size of array on each axis.
  4. Ndarray.dtype:-It will describe the elements located in an array using python element.
  5. Ndarray.itemsize:-will refer the size of the element in an array which is measured in bytes.

Numpy functions in python

Arithmetic numpy functions :-

 

Operators

Description

1

Add()

It will return the string concatenation for two arrays of str.

2

Multiply()

Return the string with the multiple elements wise and concatenation.

3

Center()

The copy will return string with elements in string of specified length.

4

Capitalize()

It returns copy of string with only first character capitalized.

5

Lower()

It will return the element to convert into lowercase.

6

Upper()

It will return the element to convert into uppercase.

7

Splitlines()

It will  get the breaking at line boundaries

Numpy Example :-

import numpy as np
a=np.arange (9, dtype=np.float_).reshape (3, 3)
print a
b=np.array ([10, 10, 10])
print b
print np.add (a, b)
print np.substract (a, b)
print np.multiply (a, b)
print np.divide (a, b)
Output:-
a: -                 [[0. 1. 2.]
[3. 4. 5.]
[6. 7.  8.]]
b:-
[10 10 10]
Add two arrays:-
[[10. 11. 12.]
[13. 14. 15.]
[16. 17. 18.]]
Subtract two arrays:-
[[-10. -9. -8.]
[-7. -6. -5.]
[-4. -3. -2.]]
Multiply two arrays:-
[[0. 10. 20.]
[30. 40. 50.]
[60. 70. 80.]]
Divide the two arrays:
[[0. 0.1 0.2]
[0.3 0.4 0.5]
[0.6 0.7 0.8]]

The numpy mathematical function:-

It contains the large of mathematical operations and provides the standard function for arithmetic operations.
The numpy has the trigonometric functions which return the ratios if angle.

  1. The ndim is the number of axes of the array.
  2. The shape is containing the length in each dimension.
  3. The size has the total number of elements.

Sr.no

Parameter and description

1

A:is called as the input data

2

Decimals:-
It is the number of decimals to round and the default value is 0.

Trigonometric functions are:-


Function

Description

tan

It is used to compute the tangent element-wise.

arcos()

It is inverse cosine element wise

arcsin()

It is the inverse sine element wise.

arctan()

It’s the trigonometric tangent function.

degrees()

Used to convert the angles from radians to degree.

Rad2deg()

It converts from radian to degree

Deg2rad

It converts from degree to radian

Functions for generating the arrays :-

A. Array with arrange ():-

It will create an array which is spaced values between the start, end, and increment.
It is used to change the dimension of array in Numpy.
Syntax:-
np.arange (Start, End, Increment)
Example:-
import numpy as np
a=np.arange (4)
a1=np.arange (0, 12, 2)
print (a)
 a2=np.arange (0, 12, 2).reshape (2, 3)
print(a2)
a3=np.arange (9).reshape (3, 3)
print (a3)

 Output:-
[0 1 2 3 4]
[0 2 4 6 8 10]
[0 2 4]
[6 8 10]]
[[0 1 2]
[3 4 5]
[6 7 8]]

B.Array with line space:-

The linespace () will generate an array with eventually spaced values between the start and end values using the specified number of the element.
Syntax:-
np.linespace (start, end, number of elements)
Example:-
import numpy as np
a1=np.linespace (1, 12, 2)
print(a1)
a1=np.linespace (1, 12, 4)
print(a1)
a2=np.linespace (1, 12, 2).reshape (4, 3)
print(a2)
Output:-
[1.12.]
[1.   4.66 8.33
[[1. 2. 3.]
[4. 5. 6.]
[7. 8. 9.]
[10. 11. 12.]]

C.Array with logspace ():-

This function will generate the arrays with values like logarithmically spaced between the start and end values.
Example:-
import numpy as np
a=np.logspace (5, 10, num=10, base=10000, dtype=float)
print(a)
Output:-
[1.000e+357.7e+385.99e+424e+463.59+502.7e+542.12e+581.6e+621.2e+661.00e+70]

 

D.Full array:-

Used to generate the array specified by dimensions and the data type that is filled by specified the number.
Example:-
import numpy as np
a1=np.full ((3), 2)
print(a1)       
a2=np.full ((2, 4), 3)
print (a2)
Output:-
[2 2 2]
[[3 3 3 3]
[3 3 3 3]]

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India