SymPy中眼睛和身份之间的区别 [英] Difference between eye and Identity in SymPy

查看:83
本文介绍了SymPy中眼睛和身份之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SymPy中,eye(5)Identity(5)有什么区别?

In SymPy, what is the difference between eye(5) and Identity(5)?

如果我有一个矩阵X,我会看到X + eye(5)X + Identity(5)给出不同的结果(后者不是矩阵).

If I have a matrix X, I see that X + eye(5) and X + Identity(5) give different results (the latter is not a matrix).

推荐答案

SymPy进行区分

  • 显式矩阵,具有一定的大小,例如3 x 3,并带有显式(可能是符号)条目;
  • 矩阵表达式,可能具有符号大小,如n乘n.
  • explicit matrices, which have certain size, like 3 by 3, and explicit (possibly symbolic) entries;
  • matrix expressions, which may have symbolic size, like n by n.

eye创建一个矩阵,Identity创建一个矩阵表达式.例如:

eye creates a matrix, Identity creates a matrix expression. For example:

n = Symbol("n")
A = Identity(n)  # works
A = eye(n)       # throws an error

一个人可以对此对象进行一些计算,例如

One can do some computations with this object, such as

t = trace(A)     # n
B = BlockMatrix([[A, -A], [-A, A]])

如果可能,可以使用as_explicit方法将矩阵表达式转换为显式矩阵:

When possible, a matrix expression can be turned into an explicit matrix with as_explicit method:

A = Identity(3)
print(A.as_explicit())

打印

Matrix([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])

一个人可以使用Matrix(A)达到相同的效果.

One can use Matrix(A) to the same effect.

这篇关于SymPy中眼睛和身份之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆