[Python] Is there a numpy function that allows you to specify start, step, and number?

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    We're all familiar with np.linspace, which creates an array given a start, stop, and num of elements:

    In [1]: import numpy as np

    In [2]: np.linspace(0, 10, 9)
    Out[2]: array([ 0. , 1.25, 2.5 , 3.75, 5. , 6.25, 7.5 , 8.75, 10. ])


    Likewise, who could ever forget np.arange, which creates an array given a start, stop, and step:

    In [4]: np.arange(0, 10, 1.25)
    Out[4]: array([ 0. , 1.25, 2.5 , 3.75, 5. , 6.25, 7.5 , 8.75])


    But is there a function that allows you to specify a start, step, and num of elements, while omitting the stop? There should be.

    Continue reading...

Compartilhe esta Página