Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Python 3 Suppose you have a four-dimensional array A[, j, k, 1] with dimensions, 1-0, ,10 ], j= != [O, , 10], where 10
In Python 3
Suppose you have a four-dimensional array A[, j, k, 1] with dimensions, 1-0, ,10 ], j= != [O, , 10], where 10 , j0 , k0 , 10, are user defined parameters, write a program that splits the array in four blocks according to the index sets: Block 1: = [0, , 10 //2], j [0, , j0 //2], k [0, , koj, I = [0, , 10] Block 2: = [0, , 10 //2], j = [j 0 //2+1, , j 0 ], k = [0, , k 0 ], 1 = [0, , 10] Block 3: = [ 0//2 + 1, , 10], j = [0, , jo //2], k = [0, , k 0 ], 1 = [0, , 101 where A must be set such that: A[ , j, k, 1 ] =l in Block 1, A[,j,k,l] Block 4. -2 in Block 2, A[ , j, k, 1 ] -3 in Block 3, A[i,j,k,1] -4 in Your program must create an iterator to traverse each block, setting the values using a for loop. For instance, the code below builds an iterator to traverse all elements of an (3,3,3,3) array;: In [ import numpy as np from itertools import product M-np.zeros ( (3,3,3)) cids - product ( (0,1,2), (0,1,2),(0,1,2)) for i in cids: M[1] += 1 print(i) print(M) Create a function build_4Darray (i0,j0,ko,10) that receive the four dimensions and return the array with values set in the blocks as defined above. Run the tests below to ensure the array is built correctly: In [ ] Abuild _4Darray (2,4,3,3) assert AI0,1,1,0]- 1 assert AI0,3,1,012 assert A[2,1,1,0]-3 assert A[2,3,1,0]-4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started