打印为例:撤消漂亮从numpy的
from numpy import *
A = array([2/3., 4])
print A
给人
[ 0.66666667 4. ]
如何把字符串:
S = "[ 0.66666667 4. ]"
,并转换S
回到A
使用numpy
电话只要?我有一个黑客解决方案,但似乎应该有一个这样做的numpy内置。我看着fromstring,但是当我直接使用它,它给我的错误:
fromstring(S)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: string size must be a multiple of element size
它可能是,如果你可以'再版(A)'或'印刷再版(A)'更容易,那么你可以使用'ast.literal_eval'。 – 2012-03-09 22:42:22