0
I am doing a program in python that uses matrices, I am using numpy to do them, but it is giving the following problem: I do the matrix in order to save several values, but it keeps only one. I was first making a list and dps converting to array using np.array(), but I wanted to do it another way, could I? Follow below my program:
import numpy as np #
import math # importando bibliotecas para criação das matrizes e cálculos com
# números reais, respectivamente.
n1=n2=1 # definindo constantes
pi = math.pi #
M = 200
#
gama1 = 2/3 #
b1 = math.sqrt(gama1) / (1+math.sqrt(1-gama1)) #
gama2 = 2/3 # definindo os valores de b1 e b2 #
b2 = math.sqrt(gama2) / (1+math.sqrt(1-gama2)) #
for l in range(1,M+1):
for c in range(1,n1+1):
w1 = np.array([b1*math.sqrt(1/(pi*(M+1)))*math.sin((l*c*pi)/(M+1))]) # adicionando valor na lista
for c in range(1,n2+1):
w2 = np.array([b2*math.sqrt(1/(pi*(M+1)))*math.sin((l*(n1+c)*pi)/(M+1))]) # adicionando valor na lista
in case the matrices are w1 and w2, and instead of appearing a 1x200 matrix, shows a 1x1 matrix
is pq at each loop you set the variable again. Then at the end you get only one list. You can use
np.append
to join the list to each loop.– Lucas
I didn’t understand how to use this function, I used it in the program, but it didn’t work. I could give an example?
– Jefferson Monteiro
I answered. But please note the amount of information in your question and in your code that does not relate to the question. Try to leave in the question only the essential. See a guide here: https://pt.meta.stackoverflow.com/questions/1186/como-crea-um-exemplo-m%C3%adnimo-completo-e-verific%C3%a1vel
– Lucas