diff --git a/your-code/main.py b/your-code/main.py index 78c792b..bdcb363 100644 --- a/your-code/main.py +++ b/your-code/main.py @@ -1,69 +1,77 @@ #1. Import the NUMPY package under the name np. - +import numpy as np #2. Print the NUMPY version and the configuration. - +print(np.version.version) #3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable "a" # Challenge: there are at least three easy ways that use numpy to generate random arrays. How many ways can you find? +#a = np.random.random(2,3,5) +a = np.random.randint(200, size =(2, 3, 5)) -#4. Print a. +#4. Print a. +print(a) #5. Create a 5x2x3 3-dimensional array with all values equaling 1. #Assign the array to variable "b" +b = np.ones((5, 2, 3)) +#6. Print (b) -#6. Print b. - - +print(b) #7. Do a and b have the same size? How do you prove that in Python code? - +print(np.shape (a) == np.shape(b)) #8. Are you able to add a and b? Why or why not? - +#no, they should have the same shape #9. Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array to varialbe "c". - - +print(np.shape(b)) +c = b.transpose(1,2,0) +print(np.shape(c)) #10. Try to add a and c. Now it should work. Assign the sum to varialbe "d". But why does it work now? - +d = a + c #11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain. +print (f" matrix a = {a}") +print (f" matrix d = {d}") - +# both matrix have a difference of "1" between each of its elements => element_matrix_d _position_1 = element_matrix_d _position_1 + 1 #12. Multiply a and c. Assign the result to e. +e = a * c #13. Does e equal to a? Why or why not? - +print(a == e) # yes, as any number*1 = number #14. Identify the max, min, and mean values in d. Assign those values to variables "d_max", "d_min", and "d_mean" +d_max = np.max(d) +d_min = np.min(d) +d_mean = np.mean(d) - - +print(d_max,d_min,d_mean) #15. Now we want to label the values in d. First create an empty array "f" with the same shape (i.e. 2x3x5) as d using `np.empty`. - - +f = np.empty((2,3,5)) """ #16. Populate the values in f. For each value in d, if it's larger than d_min but smaller than d_mean, assign 25 to the corresponding value in f. @@ -74,7 +82,21 @@ In the end, f should have only the following values: 0, 25, 50, 75, and 100. Note: you don't have to use Numpy in this question. """ +for a in range(2): + for b in range(3): + for i in range(5): + if d_min < d[a][b][i]