numpy.linspace is used to create a one-dimensional array, and it is a one-dimensional array composed of an arithmetic sequence. The following article mainly introduces you to the relevant information about linspace in the python numpy function to create an arithmetic sequence. The article introduces it in detail through sample code. Friends in need can refer to it.
Preface
This article mainly introduces to you the relevant content about linspace creating arithmetic sequence, and shares it for your reference and study. Below Not much to say, let’s take a look at the detailed introduction.
numpy.linspace is used to create a one-dimensional array composed of arithmetic sequences. The most commonly used parameters are three, but of course there are more than three.
The first example uses three parameters. The first parameter represents the starting point, the second parameter represents the ending point, and the third parameter represents the number of the sequence.
import numpy as np print(np.linspace(1,10,10,endpoint=False))
Create an arithmetic sequence with all elements being 1, or an arithmetic sequence with all elements being 0.
import numpy as np print(np.linspace(1,1,10))
You can use the parameter endpoint to determine whether to include the termination value. If this parameter is not set, the default is True.
import numpy as np print(np.linspace(1,10,10,endpoint=False))
You can also use two parameters to create an array. When two parameters are passed in, the first parameter represents the starting point. , the second parameter represents the end point, the default number is 50.
import numpy as np print(np.linspace(1,50))
To verify, we use three parameters, and the results are obviously consistent.
import numpy as np print(np.linspace(1,50,50))
You can also look at the data format of the elements of the array created by linspace, which is of course floating point.
Summarize
The above is the detailed content of Example sharing of creating arithmetic sequence using linspace in python numpy function. For more information, please follow other related articles on the PHP Chinese website!