Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/lab-numpy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 102 additions & 39 deletions your-code/main.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,110 @@
#1. Import the NUMPY package under the name np.
# 1.- Import the NUMPY package under the name np.
import numpy


# 2. Print the NUMPY version and the configuration.
numpy_version = numpy.version
print("Version:", numpy_version.version)

#2. Print the NUMPY version and the configuration.



#3. Generate a 2x3x5 3-dimensional array with random values. Assign the array to variable "a"
# 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 = numpy.random.random((2, 3, 5))


# 4. Print a.
print("a: ", a)

#4. Print a.



#5. Create a 5x2x3 3-dimensional array with all values equaling 1.
#Assign the array to variable "b"



#6. Print b.



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

# 5. Create a 5x2x3 3-dimensional array with all values equaling 1.
# Assign the array to variable "b"
b = numpy.ones((5, 3, 2))


# 6. Print b.
print("b:", b)

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

# 7. Do a and b have the same size? How do you prove that in Python code?
print("Same Size A and B?", len(a) == len(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".
# 8. Are you able to add a and b? Why or why not?
try:
numpy.add(a, b)

except:
print("No son del mismo tamaño")


#10. Try to add a and c. Now it should work. Assign the sum to varialbe "d". But why does it work now?
# 9. Transpose b so that it has the same structure of a (i.e. become a 2x3x5 array). Assign the transposed array
# to variable "c".
c = numpy.transpose(b)
print("c:", c)


# 10. Try to add a and c. Now it should work. Assign the sum to varialbe "d". But why does it work now?
try:
d = numpy.add(a, c)
except:
print("operands could not be broadcast together with shapes/ No son del mismo tamaño")

#11. Print a and d. Notice the difference and relation of the two array in terms of the values? Explain.
print("a-shape: ", a.shape, "c-shape", c.shape)


# 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: ", d)
# Numpy realizó una suma entre arreglos, sumando 1 a todos los datos del array


#12. Multiply a and c. Assign the result to e.
# 12. Multiply a and c. Assign the result to e.
e = numpy.multiply(a, c)
print(a, c)
print("e:", e)


# 13. Does e equal to a? Why or why not?
print("e equeal to a?", a == e)
# Porque solo se multiplico x1

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

# 14. Identify the max, min, and mean values in d. Assign those values to variables "d_max", "d_min", and "d_mean"
d_max = d.max()
d_min = d.min()
d_mean = d.mean()
print("Max:", d_max, "Min:", d_min, "Mean:", d_mean)



#14. Identify the max, min, and mean values in d. Assign those values to variables "d_max", "d_min", and "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`.


# 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 = numpy.empty((2, 3, 5),dtype=object)


"""
#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.
#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.
If a value in d is larger than d_mean but smaller than d_max, assign 75 to the corresponding value in f.
If a value equals to d_mean, assign 50 to the corresponding value in f.
Assign 0 to the corresponding value(s) in f for d_min in d.
Assign 100 to the corresponding value(s) in f for d_max in d.
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(len(d)):
for j in range(len(d[0])):
for k in range(len(d[0, 0])):
if d[i, j, k] > d_min and d[i, j, k,] < d_mean:
f[i, j, k] = "B"
elif d[i, j, k] > d_mean and d[i,j,k,] < d_max:
f[i, j, k] = "D"
elif d[i, j, k] == d_mean:
f[i, j, k] = "C"
elif d[i, j, k] == d_min:
f[i, j, k] = "A"
elif d[i, j, k] == d_max:
f[i, j, k] = "E"
print("F:", f)


"""
Expand All @@ -98,11 +127,13 @@
[ 75., 75., 75., 75., 75.],
[ 25., 75., 0., 75., 75.]]])
"""
print(d)
print(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:
("A=0", "B=25", "C=50", "D=75", and "E=100") to label the array elements? You are expecting the result to be:
array([[[ 'D', 'D', 'D', 'B', 'D'],
[ 'D', 'D', 'B', 'B', 'B'],
[ 'D', 'B', 'D', 'D', 'D']],
Expand All @@ -111,4 +142,36 @@
[ 'D', 'D', 'D', 'D', 'D'],
[ 'B', 'D', 'A', 'D', 'D']]])
Again, you don't need Numpy in this question.
"""
"""
'''''''''
g = numpy.chararray((2,3,5))
for i in range(len(d)):
for j in range(len(d[0])):
for k in range(len(d[0,0])):
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)
'''''''''''

for i in range(len(d)):
for j in range(len(d[0])):
for k in range(len(d[0, 0])):
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
print("F:", f)