NumPhp::linspace

Create a range with a defined number of values.

Description

SciPhp\NdArray NumPhp::linspace( mixed $start , mixed $stop [, int $num = 50 ] [, bool $endpoint = true ])

Parameters

$start
A float or an integer.
$stop
A float or an integer.
$num
An integer. The number of values
$endpoint
A boolean. If True, stop is the last element. Otherwise, it is not included. Default is True.

Return Values

The new SciPhp\NdArray

Examples

Example #1: Creating a range of integers

use SciPhp\NumPhp as np;

$x np::linspace(150);

echo 
$x;

The above example will output:

[1   2   3  ...  48  49  50]

The default number of values is 50

Example #2: Creating a range of 9 float numbers

use SciPhp\NumPhp as np;

$x np::linspace(129);

echo 
$x;

The above example will output:

[1      1.125  1.25   1.375  1.5    1.625  1.75   1.875  2    ]

Example #3: Creating a range of 10 float numbers which does not contain the maximum value

use SciPhp\NumPhp as np;

$x np::linspace(1210false);

echo 
$x;

The above example will output:

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

See Also