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
101 changes: 85 additions & 16 deletions your-code/main.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,83 @@
#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.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.full((5,2,3),1)



#6. Print b.

print(b)


#7. Do a and b have the same size? How do you prove that in Python code?

if a.size == b.size:
print("True")
else:
print("False")



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

a+b


#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 = np.reshape(b,(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 = a+c
print(d) #las dimensiones son las mismas para poder ejecutar la suma



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


print(a)
print(d)
#se sumo "1" a la matriz 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?

print("Si por que se multiplico a por 1")



#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.amax(d)
print(d_max)
d_min = np.amin(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)


"""
Expand All @@ -74,7 +89,33 @@
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.
"""

temp = []

for i in d:
#print(i)
for j in i:
#print(j)
for x in j:
##print(x)
if x > d_min and x < d_mean:
temp.append(25)
#print("25")
elif x > d_mean and x <d_max:
temp.append(75)
#print("75")
elif x == d_mean:
temp.append(50)
#print("50")
elif x == d_min:
temp.append(0)
#print("0")
elif x == d_max:
temp.append(100)
# print("100")
#

f= np.reshape(temp,(2,3,5))
print(f)



Expand All @@ -98,7 +139,7 @@
[ 75., 75., 75., 75., 75.],
[ 25., 75., 0., 75., 75.]]])
"""

print(f)

"""
#18. Bonus question: instead of using numbers (i.e. 0, 25, 50, 75, and 100), how to use string values
Expand All @@ -111,4 +152,32 @@
[ 'D', 'D', 'D', 'D', 'D'],
[ 'B', 'D', 'A', 'D', 'D']]])
Again, you don't need Numpy in this question.
"""
"""
temp = []

for i in d:
#print(i)
for j in i:
#print(j)
for x in j:
##print(x)
if x > d_min and x < d_mean:
temp.append('B')
#print("25")
elif x > d_mean and x <d_max:
temp.append('D')
#print("75")
elif x == d_mean:
temp.append('C')
#print("50")
elif x == d_min:
temp.append('A')
#print("0")
elif x == d_max:
temp.append('E')
# print("100")
#

f = np.reshape(temp,(2,3,5))
print(f)