• PHP Video Tutorials

PHP - Stats Stat Innerproduct() Function



Definition and Usage

The stats_stat_innerproduct() function can return an inner product of two vectors.

Syntax

  float stats_stat_innerproduct( array $arr1, array $arr2 )

Parameters

Sr.No Parameter Description
1

arr1

The first array

2

arr2

The second array

Return Values

The stats_stat_innerproduct() function can return an inner product of arr1 and arr2, or false on failure.

Dependencies

This function was first introduced in statistics extension (PHP 4.0.0 and PEAR 1.4.0). We have used latest release of stats-2.0.3 (PHP 7.0.0 or newer and PEAR 1.4.0 or newer) for this tutorial

Example

In the following example, we compute an inner product of arr1 and arr2.

<?php
   var_dump(stats_stat_innerproduct(array(1, 2), array(3, 4)));
?>

Output

This will produce following result −

float(11)

Example

Following is an error case. In the following example, we pass unequal length arrays. A warning is displayed in logs.

<?php
   // error cases
   var_dump(stats_stat_innerproduct(array(1, 2), array(3, 4, 5)));
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_stat_innerproduct(): Unequal number of X and Y coordinates

bool(false)
Advertisements