logo

numpy.arange() în Python

The arange([start,] stop[, step,][, dtype]): Returnează o matrice cu elemente uniform distanțate conform intervalului. Intervalul menționat este pe jumătate deschis, adică [Start, Stop)

Parametri:



 start :  [optional] start of interval range. By default start = 0 stop :  end of interval range step :  [optional] step size of interval. By default step size = 1, For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. dtype :  type of output array>

Întoarcere:

Array of evenly spaced values. Length of array being generated = Ceil((Stop - Start) / Step)>

Exemplu:

Python3








# Python Programming illustrating> # numpy.arange method> import> numpy as geek> print>(>'A '>, geek.arange(>4>).reshape(>2>,>2>),>' '>)> print>(>'A '>, geek.arange(>4>,>10>),>' '>)> print>(>'A '>, geek.arange(>4>,>20>,>3>),>' '>)>

converti strin în int
>

>

Ieșire:

A [[0 1] [2 3]] A [4 5 6 7 8 9] A [ 4 7 10 13 16 19]>

Notă:

  • Aceste programe NumPy-Python nu vor rula pe ID online, așa că rulați-le pe sistemele dvs. pentru a le explora.
  • Avantajul numpy.arange() față de funcția normală încorporată range() este că ne permite să generăm secvențe de numere care nu sunt numere întregi.

Exemplu:

Python3




fișier csv citiți java
# Python Programming illustrating> # numpy.arange method> import> numpy as np> # Printing all numbers from 1 to> # 2 in steps of 0.1> print>(np.arange(>1>,>2>,>0.1>))>

>

>

Ieșire:

[1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9]>

Dacă o încercați cu funcția range(), veți obține o TypeError.