Solucion al reto
Problema 1
def vectores_unitarios(n):
vector_u = []
for i in range(n):
array = np.zeros(n)
array[i] = 1
vector_u.append(array)
return vector_u
vectores_unitarios(4)
[array([1., 0., 0., 0.]),
array([0., 1., 0., 0.]),
array([0., 0., 1., 0.]),
array([0., 0., 0., 1.])]
Problema 2
def combinacion_lineal(escalares, vectores):
combinaciones = [np.array(i * j) for i, j in zip(escalares, vectores)]
return sum(combinaciones)
print('Combinacion lineal 1 = ',combinacion_lineal([1, 1, 1], vectores_unitarios(3)))
print('Combinacion lineal 2 = ',combinacion_lineal([-1, 1, 1], np.array([[2, 2, 2], [2, 2, 2], [1, 1, 1]])))
print('Combinacion lineal 3 = ',combinacion_lineal([-1, 1, 1/3], np.array([[3, 3, 3], [3, 3, 3], [3, 3, 3]])))
Combinacion lineal 1 = [1. 1. 1.]
Combinacion lineal 2 = [1 1 1]
Combinacion lineal 3 = [1. 1. 1.]
Problema 3
def sum1_coef(n_coef, size):
data = []
for i in range(size):
coef = np.random.rand(2)
coef = np.linspace(min(coef), max(coef), n_coef-1)
coef = np.append(coef, 1 - sum(coef))
data.append(coef)
return data
sum1_coef(3, 3)
[array([0.14405631, 0.38670477, 0.46923892]),
array([ 0.04266722, 0.96290285, -0.00557008]),
array([ 0.73777766, 0.99145253, -0.72923019])]
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?