Home > Backend Development > Python Tutorial > Example sharing of creating arithmetic sequence using linspace in python numpy function

Example sharing of creating arithmetic sequence using linspace in python numpy function

黄舟
Release: 2017-10-14 10:25:52
Original
3064 people have browsed it

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))
Copy after login
Copy after login

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))
Copy after login

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))
Copy after login
Copy after login

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))
Copy after login

To verify, we use three parameters, and the results are obviously consistent.


import numpy as np
print(np.linspace(1,50,50))
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template