Я создал две программы для запуска c моделирования системы химических реакций. В программе у меня есть функция, которая предназначена для обновления элементов массива с помощью derivative
изменяющихся номеров молекул popul_num
и сточастей c константы скорости каждой реакции stoch_rate
В первой программе функция выглядит следующим образом:
popul_num = np.array([1.0E9, 0, 0])
stoch_rate = np.array([1.0, 0.002, 0.5, 0.04])
def update_array(popul_num, stoch_rate):
"""Specific to this model
will need to change if different model
implements equaiton 24 of the Gillespie paper"""
# calcualte in seperate varaible then pass it into the array
s_derviative = stoch_rate[1]*(2*popul_num[0] -1)/2
b = np.array([[1.0, 0.0, 0.0], [s_derviative, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.4, 0.0]])
return b
Эта функция возвращает b
, что является array
из shape(4, 3)
В следующей программе я добавил больше реакций и больше реагентов и функция выглядит следующим образом:
popul_num = np.array([1.0E5, 3.0E5, 0.0, 1.0E5, 0.0, 0.0, 0.0, 0.0])
stoch_rate = np.array([0.015, 0.00016, 0.5, 0.002, 0.002, 0.8])
def update_array(popul_num, stoch_rate):
"""Specific to this model
will need to change if different model
implements equaiton 24 of the Gillespie paper"""
s_derivative = stoch_rate[0]*popul_num[1]*((popul_num[1] - 1)/2) # derivative with respect to S is a function of X
x_derivative = stoch_rate[0]*popul_num[0]*((2*popul_num[1] - 1)/2) # derivative with respect to X is a function of S
r_derivative = stoch_rate[1]*((popul_num[3]*(popul_num[3]))/2)
r2_derivative = stoch_rate[2]*popul_num[4] # derivative with respect to R is a function of Y type = numpy.float64
y_derivative = stoch_rate[3]*popul_num[3] # derivative with respect to Y is a function of R type = numpy.float64
x2_derivative = stoch_rate[4]*((popul_num[1] - 1)/2)
b = np.array([[x_derivative, s_derivative, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0,
r_derivative, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, r2_derivative, y_derivative, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, stoch_rate[3], 0.0, 0.0, 0.0, 0.0], [x2_derivative, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, stoch_rate[5], 0.0]])
b.reshape((6,8))
print("Shape b:\n", b.shape)
return b
Только это возвращает array
из shape(6,)
, и мне нужно, чтобы это был 2D-массив shape(6, 8)
Я пробовал использовать метод reshape()
, но это приводит к следующей ошибке:
ValueError: cannot reshape array of size 6 into shape (6,8)
Которая появляется в строке, где я вызываю команду reshape()
Я не понимаю, чем отличается вторая функция, что означает, что она не 'Не вернуть 2D-массив?
Ура