-7

I am not able to do this exercise:

Array x= ([32, 14, 6, 4, 9, 11, 53, 23, 7, 12, 54, 3]) and utilize numpy

a. Convert the above array x into a new 3 by 4-dimensional array b. Set all values of the second raw to 5 c. Find mean, median, variance and standard deviation of each raw d. Slice the third column of the new array

Would you be able to help me? Thank you in advance.

Arthur
  • 9
  • 1
  • https://stackoverflow.com/questions/12575421/convert-a-1d-array-to-a-2d-array-in-numpy I guess this question is duplicated – Damotorie Jan 30 '19 at 01:11
  • A suggestion: one can use `for` loop to solve first part, i.e. to create 3 by 4-dimensional array. Post your attempt here so that experts can help you further. – rnso Jan 30 '19 at 01:13
  • quest a. I did : import numpy as np x = ([32, 14, 6, 4, 9, 11, 53, 23, 7, 12, 54, 3]) y = np.reshape(x,(3,4)) – Arthur Jan 30 '19 at 01:19

1 Answers1

-2

This does't seem like a hard exercise. But anyway.

question b you can access a raw of a numpy array like y[x,:] and a column like y[:,x] so you can change the 2nd raw using the code y[1,:] = 5.

question c numpy has functions to find all those. np.mean(), np.median(), np.var(), np.std(). you can use the function in a loop to go through you raws for that.

question d you can slice the last column like this z = y[:, -1, None]. or if you want to slice a ray it the None should be in the 2nd position.

Eshaka
  • 974
  • 1
  • 14
  • 38