logo

Python の numpy.arange()

arange([開始,] 停止[, ステップ,][, dtype]) : 間隔に従って等間隔の要素を含む配列を返します。記載された間隔は半開きです、つまり [開始、停止)

パラメーター :

 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>

戻る:



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

例:

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>),>' '>)>

ラテックステーブル
>

>

出力:

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

注記:

  • これらの NumPy-Python プログラムは onlineID では実行されないため、システム上で実行して調べてください。
  • 通常の組み込み range() 関数に対する numpy.arange() の利点は、整数ではない一連の数値を生成できることです。

例:

Python3




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>))>

>

>

出力:

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

range() 関数で実行すると、TypeError が発生します。