使用SympPy矩阵进行numpy.linalg.eig时的TypeError

时间:2015-11-21 11:05:44

标签: python numpy sympy

以下代码可以正常使用

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    boolean first =settings.getBoolean("first",false);
    String rings=settings.getString("ringtone","Default Rings");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
      Intent intent= new Intent(MainActivity.this,SettingClass.class);
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

导致输出

import numpy.linalg as nplin
T = [[1,0],[0,1]]
nplin.eig(T)

但是,如果我尝试使用来自sympy的(array([ 1., 1.]), array([[ 1., 0.], [ 0., 1.]])) 对象,

Matrix

我收到以下错误

import numpy.linalg as nplin
from sympy import Matrix
T = Matrix([[1,0],[0,1]])
nplin.eig(T)

即使我将SymPy Matrix对象转换为NumPy数组,

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

我仍然得到同样的错误。这里似乎有什么问题?

我正在使用import numpy.linalg as nplin import numpy from sympy import Matrix T = numpy.array(Matrix([[1,0],[0,1]])) nplin.eig(T) Python 2.7.9NumPy 1.8.2

0 个答案:

没有答案