在Numpy Arrays中存储字符串时出错

时间:2015-09-06 02:24:26

标签: python arrays numpy

我正在尝试将字符串存储在numpy数组中,但是,我在我定义J的行上不断收到此错误“TypeError:数据类型不理解”。我必须将这4个值存储在2x2矩阵中我相信我不能使用chararray。还有其他方法吗?

我是一个菜鸟,想要学习,你可以解释得越多越好!

由于

import numpy as np
import math as math
L1=1
L2=1.5 * L1
theta = 40 * math.pi / 180

#initial guesses

L3 = 1.5
alpha = 30 * math.pi / 180
epsilon = 1
n = 0

while epsilon > 0.0001:
    g1 = L1 * math.cos(theta) + L2 * math.cos(alpha) - L3
    dg1dalpha = -L2 * math.sin(alpha)
    dg1dL3 = -1;

    g2 = L1 * math.sin(theta) - L2 * math.sin(alpha)
    dg2dalpha = -L2 * math.cos(alpha);
    dg2dL3 = 0

    J = np.array(['dg1dalpha', 'dg1dL3'], ['dg2dalpha', 'dg2dL3'])

    s = np.array([alpha], [L3]) - J/np.array([g1], [g2])

    epsilon_alpha = abs(s[1] - alpha)

    epsilon_L3 = abs(s[2] - L3)

    epsilon = max(epsilon_alpha, epsilon_L3)

    alpha = s[1]

    L3 = s[2]

    n = n + 1

print(n, alpha, L3)

0 个答案:

没有答案