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: {xi,j,k : 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: {*i,j,l :1

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
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:
{xijk : 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<i< 5; 1 < j< 4}, {xi,j,2 :1<i< 5;1 <j < 4} and {rij3 : 1<i< 5;1 <j< 4}.
Similarly apply (testArray, c(1,3), tmpFn) means that indices i and k are retained in the answer and
the function tmpFn is applied to 15 vectors: {r1,j,1 :1<j< 4}, {x1,j,2 : 1<j< 4}, etc.
The expression apply(testArray, c(3,1), tmpFn) does the same calculation but the format of the an-
swer is different: when using apply in this manner, it is always worth writing a small example in order to
check that the format of the output of apply is as you expect.
(a) Write a function testFn which takes a single argument which is a 3-dimensional array. If this array
is denoted {rij,k : i = 1, 2,..., d1; j = 1,2,... , d2; k = 1,2, ..., d3}, then the function testFn
returns a list of the di x d2 x d3 matrix {wij.k} and the d2 x d3 matrix {zjk} where
di
di
di
Wij,k = xij,k - min rij.k
and
2j,k =
:> xijk - máx rij,k
i=1
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 =
Σ
i=1
Transcribed Image 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: {xijk : 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<i< 5; 1 < j< 4}, {xi,j,2 :1<i< 5;1 <j < 4} and {rij3 : 1<i< 5;1 <j< 4}. Similarly apply (testArray, c(1,3), tmpFn) means that indices i and k are retained in the answer and the function tmpFn is applied to 15 vectors: {r1,j,1 :1<j< 4}, {x1,j,2 : 1<j< 4}, etc. The expression apply(testArray, c(3,1), tmpFn) does the same calculation but the format of the an- swer is different: when using apply in this manner, it is always worth writing a small example in order to check that the format of the output of apply is as you expect. (a) Write a function testFn which takes a single argument which is a 3-dimensional array. If this array is denoted {rij,k : i = 1, 2,..., d1; j = 1,2,... , d2; k = 1,2, ..., d3}, then the function testFn returns a list of the di x d2 x d3 matrix {wij.k} and the d2 x d3 matrix {zjk} where di di di Wij,k = xij,k - min rij.k and 2j,k = :> xijk - máx rij,k i=1 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 = Σ i=1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY