Python矩阵问题 [英] Python matrix problems

查看:56
本文介绍了Python矩阵问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此线程的后续内容: Python矩阵,有解决方案吗?

输入

from numpy import *
import numpy

x=[['1','7'],
 ['1.5', '8'],
 ['2', '5.5'],
 ['2','9']]

代码

y = x[:, :, None] * x[:, None]
print y.sum(axis=0)

我收到错误:

列表索引必须是整数,而不是 元组"

"list indices must be integers, not tuple"

但是如果x是 x = numpy.array([[1, 7], [1.5, 8], [2, 5.5], [2, 9]])然后就可以了,但是我没有这样的输入.

But if x is x = numpy.array([[1, 7], [1.5, 8], [2, 5.5], [2, 9]]) then it's ok, but I don't have such input.

推荐答案

x转换为数字的numpy数组:

Convert x to a numpy array of numbers:

x = numpy.asanyarray([[float(z) for z in y] for y in x])

这篇关于Python矩阵问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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