From 92396da590d6c138b4b3347227e8c808f1e2e1c9 Mon Sep 17 00:00:00 2001 From: uaqro Date: Wed, 10 Jul 2019 12:23:51 -0500 Subject: [PATCH] Main.py answers to lab --- .DS_Store | Bin 0 -> 6148 bytes your-code/.DS_Store | Bin 0 -> 6148 bytes your-code/main.py | 67 +++++++++++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 .DS_Store create mode 100644 your-code/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4deab8ecf772e9c45fdbf06ef3efa08490f65c4f GIT binary patch literal 6148 zcmeHK-AWrl6h0Hvb~aL)i$cAe8=)7mBq&5Eg*A;Axe!XX)C*g5*9~=H-3iIYVAGU+ z4SfS2#V7D_>Nzu$U`WKfDsm2-`OeIoZ-)7HnI8ZUtzp~%r~-gQCoFkbEHUaQU$ByE zDI*Fq#vbg#2RMbelP+X)!&6j%zMThO@w@Fn8}58ReH^7a!e06{KBB+>XAC1^oP&lT z^kD;zF^ZwvN#__>4>O|Cpy%eej(TY_$m{hRQCca#c=<}oimbe@{0vU?D9FQnIB13a z1FC%q^OMNM-?UC=aTtA1x}(GD+s``7!zAnW4LOOsnDS#k$znZf>0uTR%s7GVkkXUh zVRdah-l}iaRAYN{Qd8q*vtCo1&F#s=lke6WpE^gU=fB5)CVwx?@`8l*sIDAHZUS7>rO4VCOFUMZn;J0wryu)c& o2L&P8F)-ROHf+c9D9XCVHO_nCkQj92gAUZ60qP=?0)MT*C$ncBLI3~& literal 0 HcmV?d00001 diff --git a/your-code/main.py b/your-code/main.py index 78c792b..4cd453d 100644 --- a/your-code/main.py +++ b/your-code/main.py @@ -1,68 +1,73 @@ #1. Import the NUMPY package under the name np. - +import numpy as np #2. Print the NUMPY version and the configuration. - +print(np.__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)) #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. - +print(b) #7. Do a and b have the same size? How do you prove that in Python code? - +print(b.size == a.size) #True if same shape a(x,y) = b(x,y), False else #8. Are you able to add a and b? Why or why not? - +#We can't add arrays with different 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". - +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? - +d = np.add(a,c) #11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain. +print(a) +print(d) - +#Each individual value of 'c' was added to the same positional value of 'a' #12. Multiply a and c. Assign the result to e. - +e = np.multiply(a,c) #13. Does e equal to a? Why or why not? - +#Yes, because we're multypliying each value for 1 which does not change values #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), dtype=float) """ @@ -75,7 +80,19 @@ Note: you don't have to use Numpy in this question. """ - +for i in range(len(f)): + for j in range(len(f[i])): + for k in range(len(f[i,j])): + if d[i,j,k] > d_min and d[i,j,k] d_mean and d[i,j,k] d_min and d[i,j,k] d_mean and d[i,j,k]