NumPhp::loadtxt

Load data from a text file.

Description

SciPhp\NdArray NumPhp::loadtxt( string $file , array $options )

Parameters

$file
A string.
$options
Defaults
[
  'headers'   => false,
  'delimiter' => ';'
]

Return Values

A SciPhp\NdArray

Examples

Example #1: Loading a matrix from a CSV file

use SciPhp\NumPhp as np;

// Load a matrix from a CSV file
$m np::loadtxt('test/data.csv');

// Construct a Vandermonde matrix
$n np::diagonal($m)->vander();

// Dot them
$r $m->dot($n);

echo 
"m\n$m""n\n$n""r\n$r";

The above example will output:

m
[[7     0.27  0.36]
 [6.3   0.3   0.34]
 [8.1   0.28  0.4 ]]
n
[[49    7     1   ]
 [0.09  0.3   1   ]
 [0.16  0.4   1   ]]
r
[[343.0819  49.225    7.63    ]
 [308.7814  44.326    6.94    ]
 [396.9892  56.944    8.78    ]]

See Also