logo
Tags down

shadow

Multiply each item in an array by each item in another array


By : sriraaj09
Date : October 16 2020, 08:10 PM
hope this fix your issue This is not beautiful but returns what you want.
a.map{|aa| b.map{|bb| bb * aa}}.flatten
code :


Share : facebook icon twitter icon

How can I multiply each item in an array easily with PHP?


By : user1924954
Date : March 29 2020, 07:55 AM
wish helps you I have an array called $times. It is a list of small numbers (15,14,11,9,3,2). These will be user submitted and are supposed to be minutes. As PHP time works on seconds, I would like to multiply each element of my array by 60. , Just iterate over the array with the foreach statement and multiply:
code :
foreach ($times as $value) {

  $new_times[] = $value * 60;

}

Multiply a 180x360 array by a 156-item time-series to get 180x360x156 array?


By : Sakshi
Date : March 29 2020, 07:55 AM
I hope this helps you . You can't have mismatched non-singleton dimensions. Permute the second argument. Assuming A is a m-by-n matrix and B is a (p-by-1) column vector:
code :
A = rand(6,5); B = rand(4,1);
% m-by-n @times 1-by-1-by-p => m-by-n-by-p
C = bsxfun(@times,A,permute(B,[3 2 1]));
size(C)
ans =
     6     5     4

How can I multiply every item in array using lambda?


By : NaahsTea
Date : March 29 2020, 07:55 AM
around this issue I want to multiply every item in this array:
code :
la = ->e{e * 2}
arr.map!(&la)
arr.map!{|e| e * 2}

Multiply two key values for each array item


By : Pranay Garg
Date : March 29 2020, 07:55 AM
it helps some times Get price of each item into an array, then finally sum it up using array_sum() -
code :
$eachPrice = array();
foreach ($items as $key => $val) {
  $eachPrice[] = $val['Price'] * $val['Quantity'];
}

$totalPrice = array_sum($eachPrice);

var_dump($totalPrice); // should be total price of all items

How can I multiply all item in an array with laravel?


By : user1454387
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further i have array in controller with output like this , Put your data in string and decode in JSON:
code :
$data = '{  
    "usia": 0.01761252446184,  
    "wife_education": 0.078277886497065,  
    "husband_education": 0.0058708414872798,  
    "number_of_children": 0.17025440313112,  
    "wife_religion": 0.86497064579256,  
    "wife_now_working": 0.078277886497065,  
    "husband_occupation": 0.23874755381605,  
    "living_index": 0.078277886497065,  
    "media_exposure": 0.048923679060665  
}';


$data = json_decode($data, true);
$product = 1;
foreach ($data as $key => $value) {
    $product *= $value;
}
shadow
Privacy Policy - Terms - Contact Us © voile276.org