This repository was archived by the owner on Jun 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaller_6.py
More file actions
160 lines (143 loc) 路 5.35 KB
/
Copy pathtaller_6.py
File metadata and controls
160 lines (143 loc) 路 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import os
#1)------------------------------------------------------------------------#
def crear_y_manipular_arrays():
A = np.arange(1, 16).reshape(3, 5)
print("Array A:\n", A)
return A
#2)------------------------------------------------------------------------#
def operaciones_basicas(A):
suma_A = np.sum(A)
media_A = np.mean(A)
producto_A = np.prod(A)
print("\nSuma de A:", suma_A)
print("Media de A:", media_A)
print("Producto de A:", producto_A)
#3)------------------------------------------------------------------------#
def acceso_y_slicing(A):
elementos_seleccionados = A[1, 1:3]
print("\nElementos seleccionados de A:", elementos_seleccionados)
#4)------------------------------------------------------------------------#
def indexacion_booleana(A):
B = A[A > 7]
print("\nArray B (elementos de A mayores que 7):\n", B)
#5)------------------------------------------------------------------------#
def algebra_lineal():
C = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
try:
determinante_C = np.linalg.det(C)
inversa_C = np.linalg.inv(C)
print("\nMatriz C:\n", C)
print("Determinante de C:", determinante_C)
print("Inversa de C:\n", inversa_C)
except np.linalg.LinAlgError:
print("\nMatriz C:\n", C)
print("La matriz C no tiene inversa (es singular).")
#6)------------------------------------------------------------------------#
def estadisticas_numpy():
D = np.random.rand(100)
maximo_D = np.max(D)
minimo_D = np.min(D)
media_D = np.mean(D)
desviacion_estandar_D = np.std(D)
print("\nValor m谩ximo de D:", maximo_D)
print("Valor m铆nimo de D:", minimo_D)
print("Media de D:", media_D)
print("Desviaci贸n est谩ndar de D:", desviacion_estandar_D)
return D
#7)------------------------------------------------------------------------#
def grafico_basico(): #graficar seno y coseno en el intervalo [-2蟺, 2蟺]
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
seno = np.sin(x)
coseno = np.cos(x)
plt.figure(figsize=(8, 6))
plt.plot(x, seno, label='Seno', color='blue', linestyle='-', linewidth=2)
plt.plot(x, coseno, label='Coseno', color='red', linestyle='--', linewidth=2)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Gr谩fico de Seno y Coseno')
plt.legend()
plt.grid(True)
plt.show()
#8)------------------------------------------------------------------------#
def graficos_dispersion(D):
indices = np.arange(len(D))
plt.figure(figsize=(8, 6))
plt.scatter(indices, D, alpha=0.7)
plt.xlabel('脥ndice')
plt.ylabel('Valor')
plt.title('Gr谩fico de Dispersi贸n de D')
plt.grid(True)
plt.show()
#9)------------------------------------------------------------------------#
def histogramas(D):
plt.figure(figsize=(8, 6))
plt.hist(D, bins=30, color='skyblue', edgecolor='black')
plt.xlabel('Valor')
plt.ylabel('Frecuencia')
plt.title('Histograma de D')
plt.grid(True)
plt.show()
#10)------------------------------------------------------------------------#
def manipulacion_imagenes():
try:
img = mpimg.imread('C:\\Users\\andyh\\Documents\\Computacion_grafica\\Codigo\\Fries.jpg')
img_gris = np.mean(img, axis=2)
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(img)
plt.title('Imagen Original')
plt.axis('off')
plt.subplot(1, 2, 2)
plt.imshow(img_gris, cmap='gray')
plt.title('Imagen en Escala de Grises')
plt.axis('off')
plt.show()
except FileNotFoundError:
print("\nError: No se encontr贸 la imagen 'Fries.jpg'.")
except Exception as e:
print(f"\nSe produjo un error al procesar la imagen: {e}")
#---------------------------------------------------------------------------#
def menu():
while True:
print("\nMen煤:")
print("1. Creaci贸n y Manipulaci贸n de Arrays")
print("2. Operaciones B谩sicas")
print("3. Acceso y Slicing")
print("4. Indexaci贸n Booleana")
print("5. 脕lgebra Lineal")
print("6. Estad铆sticas con NumPy")
print("7. Gr谩fico B谩sico")
print("8. Gr谩ficos de Dispersi贸n")
print("9. Histogramas")
print("10. Manipulaci贸n de Im谩genes con Matplotlib")
print("11. Salir")
opcion = input("Seleccione una opci贸n: ")
if opcion == '1':
A = crear_y_manipular_arrays()
elif opcion == '2':
operaciones_basicas(A)
elif opcion == '3':
acceso_y_slicing(A)
elif opcion == '4':
indexacion_booleana(A)
elif opcion == '5':
algebra_lineal()
elif opcion == '6':
D = estadisticas_numpy()
elif opcion == '7':
grafico_basico()
elif opcion == '8':
graficos_dispersion(D)
elif opcion == '9':
histogramas(D)
elif opcion == '10':
manipulacion_imagenes()
elif opcion == '11':
break
else:
print("Opci贸n no v谩lida. Intente de nuevo.")
if __name__ == "__main__":
menu()