Python Introduction to NumPy Array Manipulation














































Python Introduction to NumPy Array Manipulation



Introduction :
NumPy generally stands for Numerical Python and it is a general purpose array processing package.it always provides a high performance multidimensional array object.Numpy is usually for creating array of n dimensions.

Method Name : array.reshape(shape)
Description :Attributes of arrays: Determining the size, shape, memory consumption, and data types of arrays

In this article I will tell basic array manipulations
Method Name : Indexing of arrays
Description :Indexing of arrays: Getting and setting the value of individual array elements
Method Name : Slicing of arrays
Description :Slicing of arrays: Getting and setting smaller subarrays within a larger array
Method Name : Reshaping of arrays
Description :Changing the shape of a given array
Method Name : Joining and splitting of arrays
Description : Combining multiple arrays into one, and splitting one array into many

Method Name : array.reshape(shape)
Description : Reshaping means changing the shape of an array.This function gives a new shape to an array without changing the data.In this article shape basically tells the number of elements and dimensions of array by reshaping an array .we can also add or remove dimensions and change the number of elements in each dimension.

Parameter : arr
Description :Array to be reshaped

Parameter : newshape
Description : New shape should be compatible to the original shape int or tuple of int

Parameter : order
Description :'C' for C style, 'F' for Fortran style, 'A' means Fortran like order if an array is stored in Fortran-like contiguous memory, C style


The first step would be to give syntax
command:
array.reshape(shape)

Example :
Code :
import numpy as np array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) print("Array : " + str(array)) reshaped1 = array.reshape((2, 2, -1)) print("First Reshaped Array : ") print(reshaped1) reshaped2 = array.reshape((4, -1)) print("Second Reshaped Array : ") print(reshaped2)

Output


Comments

  • Himil
    17-Oct-2021 03:32:38 PM
    //Enter Your Comment Here...