From ec0fe8eb9e3a883e5c49717292b1476266fb5c04 Mon Sep 17 00:00:00 2001 From: davidfv7 Date: Sat, 12 Oct 2019 16:46:16 -0500 Subject: [PATCH] Main resuelto --- .vscode/settings.json | 3 ++ your-code/main.py | 114 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 21 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f99cfdd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Program Files\\Python37\\python.exe" +} \ No newline at end of file diff --git a/your-code/main.py b/your-code/main.py index 78c792b..6a95e9d 100644 --- a/your-code/main.py +++ b/your-code/main.py @@ -1,70 +1,92 @@ #1. Import the NUMPY package under the name np. - - +import numpy as np #2. Print the NUMPY version and the configuration. - +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.randint(low=1,high=9,size=(2,3,5)) #4. Print a. - +print("--------------- Variable A ----------------") +print(a) #5. Create a 5x2x3 3-dimensional array with all values equaling 1. #Assign the array to variable "b" - +b = np.full((5,2,3),1) #6. Print b. +print("--------------- Variable B ----------------") +print(b) #7. Do a and b have the same size? How do you prove that in Python code? - +sizea = a.size*a.itemsize +sizeb=b.size*b.itemsize +print("Size of a: ",sizea) +print("Size of b:",sizeb) #8. Are you able to add a and b? Why or why not? - +#No because they need to have the same dimension +try: + btemp = np.sum(a,b) + print(btemp) +except: + print("all the input arrays must have same number of dimensions") + #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("--------------- Variable C ----------------") +c = b.reshape(2,3,5) #10. Try to add a and c. Now it should work. Assign the sum to varialbe "d". But why does it work now? +print("--------------- Variable D ----------------") +d= np.add(a,c) - - +print(d) #11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain. - - +print("--------------- Diferencias ----------------") +print(a) +print(d) #12. Multiply a and c. Assign the result to e. - - +print("--------------- multiplicación ----------------") +e = np.multiply(a,c) #13. Does e equal to a? Why or why not? - +#Yes because they have the same values becasus we only multiplied by 1 +print(e) #14. Identify the max, min, and mean values in d. Assign those values to variables "d_max", "d_min", and "d_mean" +d_max= d.max() +d_min= d.min() +d_mean= np.mean(d) +print("-------------- MAX,MIN,MEAN -----------------") +print("max:",d_max) +print("min:",d_min) +print("mean:",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)) - +g = np.empty((2,3,5),dtype='object') """ #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. If a value in d is larger than d_mean but smaller than d_max, assign 75 to the corresponding value in f. @@ -74,8 +96,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. """ - - +x=0 +y=0 +z=0 +for first in d: + y=0 + for second in first: + z=0 + for third in second: + if d[x][y][z]>d_min and d[x][y][z]d_mean: + f[x][y][z]=75 + elif d[x][y][z]==d_mean: + f[x][y][z]=50 + elif d[x][y][z]==d_max: + f[x][y][z]=100 + elif d[x][y][z]==d_min: + f[x][y][z]=0 + z+=1 + y+=1 + x+=1 """ @@ -98,7 +139,11 @@ [ 75., 75., 75., 75., 75.], [ 25., 75., 0., 75., 75.]]]) """ +print("----------------------- Valores F ----------------------") +print(f) +print("----------------------- Valores D ----------------------") +print(d) """ #18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), how to use string values @@ -111,4 +156,31 @@ [ '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 + + +""" +x=0 +y=0 +z=0 +for first in d: + y=0 + for second in first: + z=0 + for third in second: + if d[x][y][z]>d_min and d[x][y][z]d_mean: + g[x][y][z]="B" + elif d[x][y][z]==d_mean: + g[x][y][z]="C" + elif d[x][y][z]==d_max: + g[x][y][z]="D" + elif d[x][y][z]==d_min: + g[x][y][z]="E" + z+=1 + y+=1 + x+=1 + + +print("---------------- Valores G --------------------") +print(g)