Programación
“Primero resuelve el problema. Entonces, escribe el código.” — John Johnson
martes, 28 de mayo de 2019
viernes, 5 de abril de 2019
martes, 26 de febrero de 2019
Graficar funciones con matplotlib
Cálculo simbólico con Sympy
Sympy permite hacer operaciones analíticas o con símbolos en lugar de con valores numéricos Al igual que en Python existen varios tipos de datos numéricos como enteros (int), decimales (float) o booleanos (bool:True, False, etc.),
http://www.iac.es/sieinvens/python-course/source/sympy.htmlSympy posee tres tipos de datos propios: Real, Rational e Integer, es decir, números reales, racionales y enteros. Estoquiere decir que Rational(1,2) representa 1/2, Rational(5,2) a 5/2, etc. en lugar de 0.5 o 2.5.https://recursospython.com/codigos-de-fuente/graficar-funciones-matplotlib/
from matplotlib import pyplot
# Función cuadrática.
def f1(x):
return 2*(x**2) + 5*x - 2
# Función lineal.
def f2(x):
return 4*x + 1
# Valores del eje X que toma el gráfico.
x = range(-10, 15)
# Graficar ambas funciones.
pyplot.plot(x, [f1(i) for i in x])
pyplot.plot(x, [f2(i) for i in x])
# Establecer el color de los ejes.
pyplot.axhline(0, color="black")
pyplot.axvline(0, color="black")
# Limitar los valores de los ejes.
pyplot.xlim(-10, 10)
pyplot.ylim(-10, 10)
# Guardar gráfico como imágen PNG.
pyplot.savefig("output.png")
# Mostrarlo.
pyplot.show()
http://webs.ucm.es/info/aocg/python/modulos_cientificos/matplotlib/index.html
https://www.youtube.com/watch?v=i8ruymr85Gg
lunes, 21 de enero de 2019
Mejores promedios Agosto Diciembre 2018
SARABIA LANDEROS MARCO POLO
VAZQUEZ BARBA PAOLA DEL PILAR
MARTINEZ RUIZ JORGE ALEJANDRO
LEZAMA LEZAMA JESUS ERNESTO
VAZQUEZ BARBA PAOLA DEL PILAR
MARTINEZ RUIZ JORGE ALEJANDRO
LEZAMA LEZAMA JESUS ERNESTO
lunes, 17 de diciembre de 2018
viernes, 19 de octubre de 2018
Lo de NumPY
import numpy as np
a = np.array([1, 2, 3]) # Create a rank 1 array
print(type(a)) # Prints "<class 'numpy.ndarray'>"
print(a.shape) # Prints "(3,)"
print(a[0], a[1], a[2]) # Prints "1 2 3"
a[0] = 5 # Change an element of the array
print(a) # Prints "[5, 2, 3]"
b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 array
print("forma")
print(b.shape) # Prints "(2, 3)"
print(b[0, 0], b[0, 1], b[1, 0]) # Prints "1 2 4"
print("Matriz")
a1 = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
print(a1)
# Two ways of accessing the data in the middle row of the array.
# Mixing integer indexing with slices yields an array of lower rank,
# while using only slices yields an array of the same rank as the
# original array:
row_r1 = a1[0, :] # Rank 1 view of the second row of a
row_r2 = a1[1:2, :] # Rank 2 view of the second row of a
print("renglon 0")
print(row_r1, row_r1.shape) # Prints "[5 6 7 8] (4,)"
print("renglon 1")
print(row_r2, row_r2.shape) # Prints "[[5 6 7 8]] (1, 4)"
# We can make the same distinction when accessing columns of an array:
col_r1 = a1[:, 0]
col_r2 = a1[:, 1:2]
print("columna 0")
print(col_r1, col_r1.shape) # Prints "[ 2 6 10] (3,)"
print("columna 1")
print(col_r2, col_r2.shape) # Prints "[[ 2]
# [ 6]
# [10]] (3, 1)"
a = np.array([1, 2, 3]) # Create a rank 1 array
print(type(a)) # Prints "<class 'numpy.ndarray'>"
print(a.shape) # Prints "(3,)"
print(a[0], a[1], a[2]) # Prints "1 2 3"
a[0] = 5 # Change an element of the array
print(a) # Prints "[5, 2, 3]"
b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 array
print("forma")
print(b.shape) # Prints "(2, 3)"
print(b[0, 0], b[0, 1], b[1, 0]) # Prints "1 2 4"
print("Matriz")
a1 = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
print(a1)
# Two ways of accessing the data in the middle row of the array.
# Mixing integer indexing with slices yields an array of lower rank,
# while using only slices yields an array of the same rank as the
# original array:
row_r1 = a1[0, :] # Rank 1 view of the second row of a
row_r2 = a1[1:2, :] # Rank 2 view of the second row of a
print("renglon 0")
print(row_r1, row_r1.shape) # Prints "[5 6 7 8] (4,)"
print("renglon 1")
print(row_r2, row_r2.shape) # Prints "[[5 6 7 8]] (1, 4)"
# We can make the same distinction when accessing columns of an array:
col_r1 = a1[:, 0]
col_r2 = a1[:, 1:2]
print("columna 0")
print(col_r1, col_r1.shape) # Prints "[ 2 6 10] (3,)"
print("columna 1")
print(col_r2, col_r2.shape) # Prints "[[ 2]
# [ 6]
# [10]] (3, 1)"
Instrumentación 5
import numpy as np
m=int(input("Dame numero de muestra, filas") )
l=int(input("Dame numero de lectura, lecturas") )
li=[]
a=[]
lisp=[]
c=1
lit=[]
s=0
for i in range(m):
for j in range(l):
li.append(int(input("Muestra %d, lectura %d" % (i,j))))#esta
lit= [li[l*i : l*(i+1)] for i in range(m)]
a = np.array(lit)
print(a)
print("Maximo ",np.max(a))
print ("Minimo ",np.min(a))
print("cada item de la lista")
for i in range(m):
s=0
for j in range(l):
print("Listas ")
print(lit[i][j])
s=s+lit[i][j]
lit[i].append(s/l)
print()
print(lit)
m=int(input("Dame numero de muestra, filas") )
l=int(input("Dame numero de lectura, lecturas") )
li=[]
a=[]
lisp=[]
c=1
lit=[]
s=0
for i in range(m):
for j in range(l):
li.append(int(input("Muestra %d, lectura %d" % (i,j))))#esta
lit= [li[l*i : l*(i+1)] for i in range(m)]
a = np.array(lit)
print(a)
print("Maximo ",np.max(a))
print ("Minimo ",np.min(a))
print("cada item de la lista")
for i in range(m):
s=0
for j in range(l):
print("Listas ")
print(lit[i][j])
s=s+lit[i][j]
lit[i].append(s/l)
print()
print(lit)
Suscribirse a:
Entradas (Atom)