4. Arrays. In order to test the functions in this question, you will need an array. We can create a three- dimensional test array as follows: testArray xijk - máx xij,k i=1 Wi,j,k = Xij,k - min xij,k...


4. Arrays. In order to test the functions in this question, you will need an array. We can create a three-<br>dimensional test array as follows:<br>testArray <- array( sample( 1:60, 60, replace=F), dim=c(5,4,3) )<br>The above line creates a 5 x 4 x 3 array of integers which can be represented in mathematics by:<br>{rijk : i = 1,2, ..., 5; j = 1,2, 3, 4; k = 1,2, 3 }<br>Note that apply (testArray, 3, tmpFn) means that the index k is retained in the answer and the function<br>tmpFn is applied to the 3 matrices:<br>{xi,j,1 :1<i< 5; 1 < j< 4}, {xi,j,2 :1<i< 5;1 <j < 4} and {rij3 :1<i< 5;1 <j< 4}.<br>Similarly apply(testArray, c(1,3), tmpFn) means that indices i and k are retained in the answer and<br>the function tmpFn is applied to 15 vectors: {r1,j,1 :1<j < 4}, {x1,j,2 : 1<j< 4}, etc.<br>The expression apply (testArray, c(3,1), tmpFn) does the same calculation but the format of the an-<br>swer is different: when using apply in this manner, it is always worth writing a small example in order to<br>check that the format of the output of apply is as you expect.<br>(a) Write a function testFn which takes a single argument which is a 3-dimensional array. If this array<br>is denoted {rijk : i = 1, 2,..., d1; j = 1,2,... , d2; k = 1,2, ..., d3}, then the function testFn<br>returns a list of the di x d2 x d3 matrix {wij.k} and the d2 x d3 matrix {zj.k} where<br>di<br>di<br>di<br>:> xijk - máx xij,k<br>i=1<br>Wi,j,k = Xij,k - min xij,k<br>and<br>Zj,k =<br>i=1<br>i=1<br>(b) Now suppose we want a function testFn2 which returns the d2 x d3 matrix {zj.k} where<br>di<br>Zj,k =<br>i=1<br>

Extracted text: 4. Arrays. In order to test the functions in this question, you will need an array. We can create a three- dimensional test array as follows: testArray <- array(="" sample(="" 1:60,="" 60,="" replace="F)," dim="c(5,4,3)" )="" the="" above="" line="" creates="" a="" 5="" x="" 4="" x="" 3="" array="" of="" integers="" which="" can="" be="" represented="" in="" mathematics="" by:="" {rijk="" :="" i="1,2," ...,="" 5;="" j="1,2," 3,="" 4;="" k="1,2," 3="" }="" note="" that="" apply="" (testarray,="" 3,="" tmpfn)="" means="" that="" the="" index="" k="" is="" retained="" in="" the="" answer="" and="" the="" function="" tmpfn="" is="" applied="" to="" the="" 3="" matrices:="" {xi,j,1="" :1="" xijk="" -="" máx="" xij,k="" i="1" wi,j,k="Xij,k" -="" min="" xij,k="" and="" zj,k="i=1" i="1" (b)="" now="" suppose="" we="" want="" a="" function="" testfn2="" which="" returns="" the="" d2="" x="" d3="" matrix="" {zj.k}="" where="" di="" zj,k="">

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here