From cf9143950ab5d0d7a66b829a135153bb1cbb1862 Mon Sep 17 00:00:00 2001 From: Ana Flavia Date: Tue, 17 Oct 2023 17:25:14 +0200 Subject: [PATCH] only did up to 16, after if have time will continue --- your-code/main.py | 70 ++++++++++++++++++++------------- your-code/tempCodeRunnerFile.py | 1 + 2 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 your-code/tempCodeRunnerFile.py diff --git a/your-code/main.py b/your-code/main.py index 78c792b..e000464 100644 --- a/your-code/main.py +++ b/your-code/main.py @@ -1,69 +1,85 @@ #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.randint(10, size = (2, 3, 5)) +#a = [1, 2, 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. - - +print("\n6-------------------------------") +print(b) #7. Do a and b have the same size? How do you prove that in Python code? - - +print("\n7-------------------------------") +print(a.size == b.size) #8. Are you able to add a and b? Why or why not? +print("\n8-------------------------------") +#result = np.add(a, b) +#result - +#not able to do it because they don't 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("\n9-------------------------------") +c = b.transpose(1,2,0) +print(c) +print(a.shape) +print(c.shape) #10. Try to add a and c. Now it should work. Assign the sum to varialbe "d". But why does it work now? - - +print("\n10-------------------------------") +d = np.add(a, c) +print("It works because we have the same shape now") #11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain. - - +print("\n11-------------------------------") +print(a) +print(d) +print("We are adding array c + array a so it's similar about size, shape but values no") #12. Multiply a and c. Assign the result to e. - - +print("\n12-------------------------------") +e = np.multiply(a,c) +print(e) #13. Does e equal to a? Why or why not? +print("\n13-------------------------------") - - +print(e == a) #14. Identify the max, min, and mean values in d. Assign those values to variables "d_max", "d_min", and "d_mean" - - - +print("\n14-------------------------------") +d_max = np.max(d) +print(d_max) +d_min = np.min(d) +print(d_min) +d_mean = np.mean(d) +print(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`. - - - +print("\n15-------------------------------") +f = np.empty((2,3,5), like = d) +print(f) +print(d) """ #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. diff --git a/your-code/tempCodeRunnerFile.py b/your-code/tempCodeRunnerFile.py new file mode 100644 index 0000000..296d654 --- /dev/null +++ b/your-code/tempCodeRunnerFile.py @@ -0,0 +1 @@ +numpy \ No newline at end of file