Developing array with specified range

Developing an array with a specified range is a common task in data analysis, machine learning, and scientific computing. There are numerous ways and functions that can be used to create a matrix. In this thread, we will explore how to develop the arrau with specified range using NumPy.

1. Using "zeros()" function and indexing:

In NumPy, the zeros() function is used to create an array of specified shape and data type, filled with zeros. You can use the zeros() function to create a matrix with the size of a specified range. Then use indexing to assign the desired values to the matrix. For example:

2. Using "reshape()" and "linspace()" function:

The linspace() function in NumPy is used to create an array of evenly spaced numbers over a specified interval. The reshape() function in NumPy is used to change the shape of an array without changing its data.
You can used linspace() function to create 1D matrix containing values of specified range and then convert it into 2D matrix using reshape() function. Example is given below:

3. Using "full()" function and indexing:

The full() function in NumPy is used to create a new array with a given shape and type, filled with a specified value or values.
You can used full() function to create a 3x3 matrix and use indexing to assign specified range of values. For specified range values, you can also create 1D matrix using arange() function. let’s code it below for better understanding.