Skip to content
Open
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
105 changes: 80 additions & 25 deletions your-code/main.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,102 @@
#1. Import the NUMPY package under the name np.

#1. Import the NUMPY package under the name np.
import numpy as np


#2. Print the NUMPY version and the configuration.

print(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?


a1 = np.random.random((2, 3, 5))
a = np.random.randint(1, 9, size=(2, 3, 5))
a2 = np.random.uniform(0.0, 5.0, (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?
print(a.size)
print(b.size)




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

#add_a_b = np.add(a, b)
#print(add_a_b)
print("No se puede porque son de diferente forma")


#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(c)

#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)
print("Sí se pudo porque tienen la misma forma")


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



print("a--->",a)
print(d)
print("Sí, la noto. A cada valor de a se le sumó el valor de c y resultó en d")

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


print("e--->",e)
print("a--->",a)
print("Sí son iguales porque c son sólo unos")


#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)
print("d_max---->", d_max)
print("d_min---->", d_min)
print("d_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`.



print("d---->", d)
f = np.empty((2,3,5))


for i, x in enumerate(d):
for j, y in enumerate(x):
for h, z in enumerate(y):
if z > d_min and z < d_mean:
f[i,j,h] = 25

elif z > d_mean and z < d_max:
f[i,j,h] = 75

elif z == d_mean:
f[i,j,h] = 50

elif z == d_min:
f[i,j,h] = 0

elif z == d_max:
f[i,j,h] = 100




"""
#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 Down Expand Up @@ -98,8 +131,8 @@
[ 75., 75., 75., 75., 75.],
[ 25., 75., 0., 75., 75.]]])
"""


print("d---->", d)
print("f---->", f)
"""
#18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), how to use string values
("A", "B", "C", "D", and "E") to label the array elements? You are expecting the result to be:
Expand All @@ -111,4 +144,26 @@
[ 'D', 'D', 'D', 'D', 'D'],
[ 'B', 'D', 'A', 'D', 'D']]])
Again, you don't need Numpy in this question.
"""
"""

w = np.empty((2,3,5), dtype=str)

for i, x in enumerate(d):
for j, y in enumerate(x):
for h, z in enumerate(y):
if z > d_min and z < d_mean:
w[i,j,h] = "B"

elif z > d_mean and z < d_max:
w[i,j,h] = "D"

elif z == d_mean:
w[i,j,h] = "C"

elif z == d_min:
w[i,j,h] = "A"

elif z == d_max:
w[i,j,h] = "E"

print(w)