Solutions Touch
← Back to all blogs

April 5, 2020

Generate dataset or return evenly spaced numbers using linspace

By Raj Thakur

Generate dataset or return evenly spaced numbers using linspace

This tutorial we will generate data for machine learning algorithm like gradient descent

In this topic, we will discuss how to generate the numerical dataset for the implementation of any mathematical algorithm. The Numpy library provides the linspace function for generating the number of the numeric set of data. Here we have decided the range of numbers or between two numbers starting point to the ending point which generates the random number between two numbers. The linspace is very powerful because it accepts negative numbers.

import matplotlib.pyplot as plt
import numpy as np
def myfunction(x):
    return x**2+x+1
x_data=np.linspace(start=-3, stop=3, num=10)
plt.xlabel('X',fontsize=12)
plt.ylabel('F(x)',fontsize=12)
plt.plot(x_data,myfunction(x_data))
plt.show()

linspace matlab plot what does numpy linspace return google numpy linspace numpy linspace 2d numpy linear sequence numpy arithmetic progression linrange python linear distribution