Skip to content
Open

:) #15

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 67 additions & 18 deletions your-code/main.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,89 @@
#1. Import the NUMPY package under the name np.


import numpy as np

#2. Print the NUMPY version and the configuration.


print("NumPy Version:", np.__version__)
print("NumPy Configuration:")
print(np.show_config())
print('FUNCIONA')

#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.rand(2, 3, 5)

# Can also use numpy.random.randint() and numpy.random.randn()

#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?



a.size == b.size

#8. Are you able to add a and b? Why or why not?

print(a+b)

#cannot add them together because they have different shapes

#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.transpose(1, 2, 0)

#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
print(d)

#it works now because the 2 arrays are now the same shape

#11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain.

print(a)
print(d)

# the values in d are the values in a+1
# because b is just an array full of ones, so even after it is transposed as c the valuse are all 1, so d just adds 1 to every value in a.


#12. Multiply a and c. Assign the result to e.


e = a*c
print(e)

#13. Does e equal to a? Why or why not?


e == a
# e = a. Because all we've done in e is multiply a x1, so the values of e are the same as a.


#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)
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`.



f = np.empty((2, 3, 5))
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.
Expand All @@ -74,9 +94,19 @@
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 i in range(2): #because there are two blocks
for j in range(3):
for k in range(5):
if d[i][j][k] > d_min and d[i][j][k] < d_mean:
f[i][j][k] = 25
elif d[i][j][k] > d_mean and d[i][j][k] < d_max:
f[i][j][k] = 75
elif d[i][j][k] == d_mean:
f[i][j][k] = 50
elif d[i][j][k] == d_min:
f[i][j][k] = 0
elif d[i][j][k] == d_max:
f[i][j][k] = 100

"""
#17. Print d and f. Do you have your expected f?
Expand All @@ -98,7 +128,10 @@
[ 75., 75., 75., 75., 75.],
[ 25., 75., 0., 75., 75.]]])
"""
print(d)
print(f)

#I did not really understand this at all, the indexing looks so complex

"""
#18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), how to use string values
Expand All @@ -111,4 +144,20 @@
[ 'D', 'D', 'D', 'D', 'D'],
[ 'B', 'D', 'A', 'D', 'D']]])
Again, you don't need Numpy in this question.
"""
"""
g = np.empty((2, 3, 5), dtype = str)
for i in range(2): #because there are two blocks
for j in range(3):
for k in range(5):
if d[i][j][k] > d_min and d[i][j][k] < d_mean:
g[i][j][k] = "B"
elif d[i][j][k] > d_mean and d[i][j][k] < d_max:
g[i][j][k] = "D"
elif d[i][j][k] == d_mean:
g[i][j][k] = "C"
elif d[i][j][k] == d_min:
g[i][j][k] = "A"
elif d[i][j][k] == d_max:
g[i][j][k] = "E"

print(g)