Numpy array in python

Numpy array in Python : In this tutorial we will study at about Numpy array in Ppython programming language. The Numpy array is the core library function for computing the python language. It will provide the multidimensional array and tools with these arrays. The Numpy array is familiar with MATLAB. Numpy arrays are the grid of values of same type and indexed by tuple of non negative integers. The dimensions of the array are same as the rank of array and have non-negative integers. While creating the Numpy array we use the broadcasting and access or manipulate the arrays. The Numpy is the multidimensional array which as the table of elements and all types of same type and with positive integers. The Numpy array is called as the Ndarray and also alis array. They will help to manipulate the arrays and numeric data use the modules.

It will allow the operations as follows:-

  1. The logical and mathematical operations.
  2. Shape manipulation and Fourier transformation.
  3. The linear, logical operations using the inbuilt functions.

Implementation of Numpy function:-

Working on windows makes sure that you have added python to PATH and don not forget to install the package such as pip used for open source libraries.
The numpy array is created by three different ways as:-

  1. Using the numpy functions.
  2. Conversion from other structures like lists.
  3. Using the special library functions.

 

The libraries used to implement Numpy array are:

Sparse:-Used to implement API for sparse arrays that are zeros.
Cupy:-It is used to implement API on the GPU with CUDA.
Dask arrays:-Used to implement API for the multicore workstations.


Parameters

Shape:-
Used to denote the shape of empty array.
Dtype:-It is desired data type for the arrays.
Order:-
The order of the data type is given.

Return

The array of data is given in dtype shape and order Then array objects will be initialized.

1. Using the Numpy functions:-

a. One dimensional array:-
Example:-
import numpy as np
array=np.arange (10)
array
The one dimensional array is an array having “arange” that is widely used to create an array.
After passing the value 10 to arrange function the array will create the an array with values from 0 to 9
Output:-
array([0,1,2,3,4,5,6,7,8,9])
b. One dimensional array:-
The output of the one dimensional array is chained with the reshape array function.
array=np.arange (10).reshape (2, 5)

Output:-
array([0,1,2,3,4],[5,6,7,8,9])

2. Conversion from other structures like lists:-

Without using the Numpy function you can create the array from python list.
Pass the python list to the array function and create the Numpy array.
Example:-
array=np.array ([1, 2, 3])
array
Output:-
array([1, 2, 3])
Create the list and pass variable name to create the Numpy array.
list= [1, 2, 3]
list
Output:-
[1, 2, 3]

C.Using the special library function:-

The function is to create and filled with the random values between 0 and 1.
Example:-
np.random.random ((2, 2))
Output:-
array([[0.1, 0.3], [0.3, 0.7]])

The Numpy function will take the 4 parameters as follows:-
Stop:-The number will represent the end of interval.
Start:-The number will represent start of the interval and by default it is zero.
Step:-The number will represent interval between each value in the range and by default value is one.
Dtype:-It is type of output array.

Operators

Description

np.array([1,2,4])

1d array

np.array([(1,2,4)])

2d array

np.arrange(start,stop,step)

Range array

Array:-


Syntax

Description

array. shape

It has dimensions with the rows and the columns.

len(array)

It indicates the length of array.

array.ndim

It is number of array dimensions.

array.dtype

It has the data type

array.astype(type)

Coverts into the data type

Placeholder

 


Operators

Description

np.linespace(0,1,2,4)

Add the values between intervals to the array of length.

np.zeros((1,2))

Creating and the array is filled with zeros.

np.ones((1,2))

It will create an array and filled with ones.

np.random.random((5,5))

It will create the random arrays.

np.empty(2,2)

It creates an empty array.

 

 

Array mathematics:-

  1. Addition :-used by the np.add(a,b)
  2. Subtraction:-np.subtract(a,b)
  3. Division:-np.divide(a,b)
  4. Square root:np.sqrt(b)
  5. Multiplication:-np.multiply(a,b)

Filling array with random values:-

Use the numpy random method to generate the multidimensional array with float between zeros and one.
Example:-
random_arr=np.random ((4, 4))
print(random_arr)
Output:-
[0.7 0.5   0.9 0.02]
[0.8  0.30 0.41 0.64]
[0.3  0.03 0.96 0.84]
[0.1 0.7   0.3    0.3]
Advantages:-

  1. The Numpy will consume less memory
  2. It has high speed compared to python list.
  3. It is also very convenient to use.

Applications:-
It is used in various applications as follows:-
Used in the image processing.

    • Matrix computations.
    • Used in the numerical analysis.
    • Use is in linear algebra
    • A phethora
Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India