如何以这种格式格式化这个numpy数组?

时间:2016-04-11 22:07:01

标签: python arrays numpy

我有一个像这样的numpy数组:

a = [[0.04393, 0.0, 0.0], [0.04393, 0.005, 0.0], [0.04393, 0.01, 0.0],[0.04393, 0.015, 0.0]]

我想在此格式化:

b = [((0.04393, 0.0, 0.0), ), ((0.04393, 0.005, 0.0), ), ((0.04393, 
0.01, 0.0), ), ((0.04393, 0.015, 0.0), )]

我该怎么做?

1 个答案:

答案 0 :(得分:3)

这样做:

a = [[0.04393, 0.0, 0.0], [0.04393, 0.005, 0.0], [0.04393, 0.01, 0.0],[0.04393, 0.015, 0.0]]
b = [ (tuple(a1),) for a1 in a]