python - python : Why this code did not work? (invalid syntax)
解决方案
There are three errors. First, print
is a function in Python 3, not a statement, so you need to use parentheses. The second is that with A*B
you are trying to multiply regular Python lists, but you cannot do that. Also, A+B
works, but it concatenates the lists instead of adding their elements, which is probably not what you wanted. You should use the definitions
A = np.array([2, 1, -1])
B = np.array([1, -1, 2])
The third is that you are trying to multiply matrices of incompatible dimensions in the third section.
By the way, the np.matrix
class is deprecated, so you should not use it.
推荐阅读
- r - 在列中搜索字符串以在 r 中合并
- symfony - 集合类型内联模板
- python-3.x - pyparsing:匹配给定列表的单词(CaselessLiteral)之一的问题
- javascript - 节点 JS:承诺解析值为“未定义”
- php - 将jQuery获得的表格单元格的值传递给php页面
- android - 从第一个编辑文本到第二个编辑文本,输入掩码不起作用
- r - RDA 可视化 - 根据 RDA1 绘制物种丰度图
- sql - SQL查询根据不同列的先前值计算行数
- reactjs - 为什么图像没有通过反应上传到服务器?
- r - 在 RStudio Connect 上部署 Shiny 应用程序时 curl 服务器证书验证失败