From 35d09bef559986485f35eb5193082a2d938c9758 Mon Sep 17 00:00:00 2001 From: elgamerjugon Date: Wed, 10 Jul 2019 13:23:01 -0500 Subject: [PATCH] Challenge terminado --- your-code/main.py | 90 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 19 deletions(-) diff --git a/your-code/main.py b/your-code/main.py index 78c792b..587d9ae 100644 --- a/your-code/main.py +++ b/your-code/main.py @@ -1,67 +1,78 @@ #1. Import the NUMPY package under the name np. - +import numpy as np #2. Print the NUMPY version and the configuration. - - +print(f"The version is: {np.version.version}") +print(f"The configuration is: {np.show_config()}") #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.randint(0,100,size = (2,3,5)) #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.random.randint(1,2,size = (5,2,3)) #6. Print b. - +print(b) #7. Do a and b have the same size? How do you prove that in Python code? - - +#Yes +print(f"The size of a is: {a.size}") +print(f"The size of b is: {b.size}") #8. Are you able to add a and b? Why or why not? +#No, the structure of the arrays are different +#print(f"Adding the 2 arrays {np.add(a,b)}") #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". - - +c = b.reshape((2,3,5)) +print(f"The value of c is \n {c}") #10. Try to add a and c. Now it should work. Assign the sum to varialbe "d". But why does it work now? +print(a.shape) +print(c.shape) +d = np.add(a,c) +print(f"The sum of a and c is:\n {d}") +#Now they have the same structure #11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain. - +print(f"The values of a are\n {a}\n The values of d are\n {d}") #12. Multiply a and c. Assign the result to e. - +e = np.multiply(a,c) +print(f"The values for e are \n {e}") #13. Does e equal to a? Why or why not? - +#Yes, because it is multiplying all the values of a with 1 #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) #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)) +print(f) @@ -74,8 +85,27 @@ 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. """ +print(f"El valor de d_min es: {d_min}") +print(f"El valor de d_max es: {d_max}") +print(f"El valor de d_mean es: {d_mean}") +for index0, value0 in enumerate(d): + for index1, value1 in enumerate(value0): + for index2, value2 in enumerate(value1): + #print(f"{index2}, {index1}, {index0}") + if int(value2) > int(d_min) and int(value2) < int(d_mean): + f[index0,index1,index2] = 25 + + elif int(value2) > int(d_mean) and int(value2) < int(d_max): + f[index0,index1,index2] = 75 + elif int(value2) == int(d_mean): + f[index0,index1,index2] = 50 + elif int(value2) == int(d_min): + f[index0,index1,index2] = 0 + + elif int(value2) == int(d_max): + f[index0,index1,index2] = 100 """ @@ -98,7 +128,7 @@ [ 75., 75., 75., 75., 75.], [ 25., 75., 0., 75., 75.]]]) """ - +print(f"F es igual a: \n {f}") """ #18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), how to use string values @@ -111,4 +141,26 @@ [ 'D', 'D', 'D', 'D', 'D'], [ 'B', 'D', 'A', 'D', 'D']]]) Again, you don't need Numpy in this question. -""" \ No newline at end of file +""" +f = np.empty((2,3,5),np.str) +for index0, value0 in enumerate(d): + for index1, value1 in enumerate(value0): + for index2, value2 in enumerate(value1): + #print(f"{index2}, {index1}, {index0}") + if int(value2) > int(d_min) and int(value2) < int(d_mean): + f[index0,index1,index2] = "B" + + elif int(value2) > int(d_mean) and int(value2) < int(d_max): + f[index0,index1,index2] = "D" + + elif int(value2) == int(d_mean): + f[index0,index1,index2] = "C" + + elif int(value2) == int(d_min): + f[index0,index1,index2] = "A" + + elif int(value2) == int(d_max): + f[index0,index1,index2] = "E" + +print(f"F es igual a: \n {f}") +