A PHP extension for scientific computing. Inspired by NumPy & NumPHP.
Everything you should need to install phpnum on your system.
- PHP 7 +
phpize
./configure
make && make install
make install
copies num.so
to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a num.ini file in /path/to/php.d
with the following contents: extension=num.so
.
- Class Num - Creates a Num object
- Class NumNdarray - Creates a N-dimensional array (ndarray) object
- Printing - Prints a ndarray object
Description: Creates a Num object
$num = new Num();
Description: Creates a N-dimensional array (ndarray) object
array: Array
ndarray: Object
$num = new Num();
$ndarray = $num->array([[1.0, 2, 3], [2, 3, 4]]);
Description: Prints a ndarray object
$num = new Num();
$ndarray = $num->array([[1.0, 2, 3], [2, 3, 4]]);
echo $ndarray;
/* output:
array([
[1,2,3],
[2,3,4]
])
*/
- getData - Data of the ndarray
- getShape - Shape of ndarray dimensions
- getNdim - Number of ndarray dimensions
- getSize - Number of elements in the ndarray
Description: Data of the ndarray
None
data: Array
$ndarray = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$ndarray->getData(); // returns array([1.0, 2, 3], [2, 3, 4])
Description: Shape of ndarray dimensions
None
shape: Array
$ndarray = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$ndarray->getShape(); // returns array(2, 3)
Description: Number of ndarray dimensions
None
ndim: LONG
$ndarray = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$ndarray->getNdim(); // returns 2
Description: Number of elements in the ndarray
None
size: LONG
$ndarray = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$ndarray->getSize(); // returns 6
Description: Return the minimum of an array
ndarray: Object
amin: Double
$ndarray = $num->array([[3.2, 1.5, 1], [2.5, 4, 2]]);
$num->min($ndarray); // returns 1
Description: Return the maximum of an array
ndarray: Object
amax: Double
$ndarray = $num->array([[3.2, 1.5, 1], [2.5, 4, 2]]);
$num->amax($ndarray); // returns 4
- add - Add an array to an other array
- sub - Subtract an array from an other array
- mult - Multiply an array by an other array
- div - an array divided by an other array
Description: Add an array to an other array
ndarray: Object
ndarray: Object
$a = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$b = $num->array([[3.2, 1.5, 1], [2.5, 4, 2]]);
echo $a->add($b);
/* output:
array([
[4.2,3.5,4],
[4.5,7,6]
])
*/
Description: Subtract an array from an other array
ndarray: Object
ndarray: Object
$a = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$b = $num->array([[3.2, 1.5, 1], [2.5, 4, 2]]);
echo $a->sub($b);
/* output:
array([
[-2.2,0.5,2],
[-0.5,-1,2]
])
*/
Description: Multiply an array by an other array
ndarray: Object
ndarray: Object
$a = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$b = $num->array([[3.2, 1.5, 1], [2.5, 4, 2]]);
echo $a->mult($b);
/* output:
array([
[3.2,3,3],
[5,12,8]
])
*/
Description: an array divided by an other array
ndarray: Object
ndarray: Object
$a = $num->array([[1.0, 2, 3], [2, 3, 4]]);
$b = $num->array([[3.2, 1.5, 1], [2.5, 4, 2]]);
echo $a->div($b);
/* output:
array([
[0.3125,1.3333333333333,3],
[0.8,0.75,2]
])
*/
- power - First array elements raised to powers from second array, element-wise
- square - Return the element-wise square of the input
- sqrt - Return the positive square-root of an array, element-wise
- exp - Calculate the exponential of all elements in the input array
- log - Natural logarithm, element-wise
- log10 - Return the base 10 logarithm of the input array, element-wise
- sin - Trigonometric sine, element-wise
- cos - Cosine element-wise
- tan - Compute tangent element-wise
- ceil - Return the ceiling of the input, element-wise
- floor - Return the floor of the input, element-wise
- fabs - Compute the absolute values element-wise
Description: First array elements raised to powers from second array, element-wise
base: Object
exponent: Object or Double
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->power($ndarray, 3);
// returns array([[0.125, 1.0], [0.0, 8.0]])
Description: Return the element-wise square of the input
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->square($ndarray);
// returns array([[0.5, 1.0], [0.0, 4.0]])
Description: Return the positive square-root of an array, element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->sqrt($ndarray);
// returns array([[0.70710678118654757, 1.0], [0.0, 1.4142135623730951]])
Description: Calculate the exponential of all elements in the input array
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->exp($ndarray);
// returns array([[1.6487212707001282, 2.7182818284590451], [1.0, 7.3890560989306504]])
Description: Natural logarithm, element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [10, 2]]);
$num->log($ndarray);
// returns array([[-0.69314718055994529, 0.0], [2.3025850929940459, 0.69314718055994529]])
Description: Return the base 10 logarithm of the input array, element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[1e-1, 1], [10, 100]]);
$num->log10($ndarray);
// returns array([[-1.0, 0.0], [1.0, 2.0]])
Description: Trigonometric sine, element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->sin($ndarray);
// returns array([[0.47942553860420301, 0.8414709848078965], [0.0, 0.90929742682568171]])
Description: Cosine element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->cos($ndarray);
// returns array([[0.87758256189037276, 0.54030230586813977], [1.0, -0.41614683654714241]])
Description: Compute tangent element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->tan($ndarray);
// returns array([[0.54630248984379048, 1.5574077246549023], [0.0, -2.1850398632615189]])
Description: Return the ceiling of the input, element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->ceil($ndarray);
// returns array([[1.0, 1.0], [0.0, 2.0]])
Description: Return the floor of the input, element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, 2]]);
$num->floor($ndarray);
// returns array([[0.0, 1.0], [0.0, 2.0]])
Description: Compute the absolute values element-wise
ndarray: Object
array: Array
$ndarray = $num->array([[0.5, 1], [0, -2]]);
$num->fabs($ndarray);
// returns array([[0.0, 1.0], [0.0, 2.0]])