Splitting an array by performing an arithmetic function in ruby -
I have an array like Ruby in Next, what is the best way to calculate the total number of units? In this example, this would be 9, while returning Thanks You find it useful to use matrix operations, especially If it is a step in incorporating the matrix, vector, and / or scalar. Matrix 'DF DET (AR1, AR2) (matrixcolum_quaker (AR2) * matrix.ro_ vector (AR1) is required. TO_A termination def NBR_letment (AR1, Arr2) arr1.size * arr2.size end example Optional If you do not want to use matrix operations, you can: < Previous> Here is an example: [3,4,5] and I want to create For diving or multiplying sub-orange, for example, I want to multiply each number from 2, 3 and 4 into the array,
[[6,9,12], [8,12,16], [ 10,15,20]]
array.count 3.
arr1 = [ 3,4,5] arr2 = [3,4,5] dot (AR1, AR2) # = & gt; [[9, 12, 15], # [12, 16, 20], # [15, 20, 25]] nbr_elements (arr1, arr2) # = & gt; 9 dot ([1,2,3], [4,5,6,7]) # = & gt; [[4, 8, 12], # [5, 10, 15], # [6, 12, 18], # [7, 14, 21]] nbr_elements ([1,2,3], [4,5] ], 6,7]) # = & gt; 12
arr2.map {| e [E] .product (arr1) .map {| E, F. E * F}}
arr1 = [1,2,3] arr2 = [4,5,6,7 ] Arr2.map {| e [E] .product (arr1) .map {| E, F. E = F}} # = & gt; [[4, 8, 12], # [5, 10, 15], # [6, 12, 18], # [7, 14, 21]]
Comments
Post a Comment