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
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...
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F01fb319d-f364-4590-ab45-48289dbd6af0%2Feb201471-c5af-42de-a839-39700273c1d8%2Fn9qts2s_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Similar questions
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY