Def Arraychangerpart1 (Myarray, Num1, Num2) : ''' Do Part 1 of The Question ''' # Your Code Here Raise Notimplementederror

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Question 1

Write a function that takes 3 arguments as follows:

(1) a 2-D numpy array, myArray, of some arbitrary size, say m rows x n columns

(2) num1, an integer

(3) num2, an integer

and does the following:

Part(1) return a new array myArray_new by replacing the last-but-one column of myArray with an
array of elements comprising the sum of the least value of each row of myArray and num1

Part(2) return a new array myArray_new2 by replacing the last row of myArray_new with an array
of elements comprising the sum of the highest value of each column of myArray_new and num2

Part(3) return a 2-D array myArray_new3 of the same shape as myArray i.e. m x n by sorting
ALL the elements of myArray_new2 from lowest to highest.

The code is broken into parts for your ease. Note: Each part must cumulatively do what is
required by the previous parts. i.e. for e.g., the function you write in Part 3 will have all the lines
of code in Part1, and Part2. Similarly, the function you write in Part 2 will have the lines of code in
Part1 and then the lines to implement Part 2.

Cumulative marks: Part1: 3, Part2: 6, Part3: 10 Thus, if you get parts 1 and 2 correct, but not part
3, you get 6 marks out of 10

def arrayChangerPart1(myArray,num1,num2):

'''

do part 1 of the question

'''

# YOUR CODE HERE

raise NotImplementedError()

In the cell below, write a function that takes two aruguments as follows:

(1) a 2-D numpy array, myArray, of some arbitrary size, say m rows x n columns, containing
numbers in the interval [0,1]

(2) a number, num1, in the interval [0,1]


and does the following:

Part(1) return the column means of myArray

Part(2) Part 2 is split into 2 steps for ease:

2a: in each column of myArray, find the index (or row number) of
the element that is closest to num1. i.e. The function in
Part2a must return a numpy array with a row number from each
column -it has number of elements equal to number of columns.

2b: return an array called myArray_new having same elements as


myArray, with one element in each column of myArray (as
identified in 2a by the row number) replaced with the respective
column's mean found in Part (1)

Part(3) return myArray_new2 by subtracting myArray_new from myArray

Part(4) return the transpose of myArray_new2

The code is broken into parts for your ease. Note: Each part must cumulatively do what is
required by the previous parts. i.e. for e.g., the function you write in Part 4 will have the lines of
code in Part1, Part2, and Part3 and then the lines to implement Part 4. Similarly, the function you
write in Part 2 will have the lines of code in Part1 and then the lines to implement Part 2.

Cumulative marks: Part1: 1, Part2a: 4, Part2b: 7, Part3: 8, Part4: 10 Thus, if you get parts 1, 2a
and 2b correct, but not parts 3 and 4, you get 7 marks out of 10

def arrayModifierPart1(myArray,num1):

"""

do part 1 of the question

"""

# YOUR CODE HERE

raise NotImplementedError()

You might also like