Javatpoint Logo
Javatpoint Logo

Numpy Arrays within the numerical range

This section of the tutorial illustrates how the numpy arrays can be created using some given specified range.

Numpy.arrange

It creates an array by using the evenly spaced values over the given interval. The syntax to use the function is given below.

It accepts the following parameters.

  1. start: The starting of an interval. The default is 0.
  2. stop: represents the value at which the interval ends excluding this value.
  3. step: The number by which the interval values change.
  4. dtype: the data type of the numpy array items.

group

Example

Output:

[0. 2. 4. 6. 8.]

Example

Output:

The array over the given range is  [10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95]

NumPy.linspace

It is similar to the arrange function. However, it doesn?t allow us to specify the step size in the syntax.

Instead of that, it only returns evenly separated values over a specified period. The system implicitly calculates the step size.

The syntax is given below.

It accepts the following parameters.

  1. start: It represents the starting value of the interval.
  2. stop: It represents the stopping value of the interval.
  3. num: The amount of evenly spaced samples over the interval to be generated. The default is 50.
  4. endpoint: Its true value indicates that the stopping value is included in the interval.
  5. rettstep: This has to be a boolean value. Represents the steps and samples between the consecutive numbers.
  6. dtype: It represents the data type of the array items.

Example

Output:

The array over the given range is  [10.  12.5 15.  17.5 20.]

Example

Output:

The array over the given range is  [10. 12. 14. 16. 18.]

numpy.logspace

It creates an array by using the numbers that are evenly separated on a log scale.

The syntax is given below.

It accepts the following parameters.

  1. start: It represents the starting value of the interval in the base.
  2. stop: It represents the stopping value of the interval in the base.
  3. num: The number of values between the range.
  4. endpoint: It is a boolean type value. It makes the value represented by stop as the last value of the interval.
  5. base: It represents the base of the log space.
  6. dtype: It represents the data type of the array items.

Example

Output:

The array over the given range is  [1.00000000e+10 3.16227766e+12 1.00000000e+15 3.16227766e+17
 1.00000000e+20]

Example

Output:

The array over the given range is  [1.02400000e+03 5.79261875e+03 3.27680000e+04 1.85363800e+05
 1.04857600e+06]

Next TopicNumPy Broadcasting





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA