A PHP extension for scientific computing. Inspired by NumPy & NumPHP.
Everything you should need to install phpnum on your system.
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
.
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]
])
*/
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
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]
])
*/
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]])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. Open source ecosystem
2. Collaboration, People, Software
3. Evaluation model