Program to plotting an array

Program to plotting an array

In this, We discuss the Program to plotting an array and What are the Python Array.


An array is a collection of objects that are stored at contiguous memory locations. This a concept used to store multiple items of the same type together. It easy to calculate the position of each element by adding an offset to a base value that is the memory location of the first element of the array (mostly it is denoted by the name of the array).

Python Array:

An array can be handled in Python by a module named array. This can be beneficial when we have to manipulate only specific information. A user can treat lists as arrays. However, you can't constraint the type of elements that store in a list. If you create arrays with the use of the array module, all elements of the same type array. An array used to store values of the same data type. 

This is the main difference between arrays and lists in Python. Python lists can contain values corresponding to different data types, arrays in python can only contain values corresponding to the same data type.

So when we want to use arrays in python language, you need to import the standard ‘array’ module. This is because the array is not an essential data type like strings, integer, etc. Arrays are the main data structure that we used in machine learning.

NumPy N-dimensional Array

In Python, arrays from the NumPy library, known as N-dimensional arrays or the ndarray, are used as the primary data structure for representing data. In Python, The N-dimensional array in NumPy for representing numerical and manipulating data in Python. NumPy (Numerical Python) is a Python library that can be used for scientific and numerical applications. It is the tool to use for linear algebra operations. 

The main data structure in NumPy is the ndarray, which is the N-dimensional array. When You working with NumPy, data in a ndarray is simply referred to as an array. It is a fixed-sized array in memory that consists of data of the same type, such as integers or floating-point values. 

The data type supported by an array can be accessed via the “dtype” attribute on the array. The dimensions of an array can be accessed through the “shape” attribute that returns a row describing the length of each dimension.

Creating an Array

Array in Python can be created by import an array module. array(data_type, value_list) is used to create an array with data type and value list specified in its arguments.

Python Code:
import numpy as np
from matplotlib import pyplot as plt
a = [1,3,6,7,8,9,10]
b = [1,2,3,4,5,6,10]
plt.xlabel('no of elements')
plt.ylabel('no of values')
plt.title('plotting of a n-array')
Program to plotting an array
Program to plotting an array

Summary: In this section we discussed array. What is an array, Python array and how to create an array in Python? we talked about the N-dimensional array which is also called ndarray used for representing numerical and manipulating data in Python. In this, we need first the important library that is used in Python Programming numpy, and matplotlib. The reason behind the use of plt here because of the declaration of matplotlib as plt. 

In this case from matplotlib import pyplot for plotting the graph. For every pyplot function makes some change to a figure: e.g., plots some lines in a plotting area, decorates the plot with x (no of elements), y labels (no. of values) and the title of the graph, plt.grid to show grid in the graph, is used to show the graph, etc. This graph is showing to plotting the elements of an array in Python Programming with code and output.