【问题标题】:python remove dtype and the end of an array and get list of listspython删除dtype和数组的末尾并获取列表列表
【发布时间】:2017-11-14 08:40:16
【问题描述】:

有谁知道如何将此数组转换为python列表,我的最终结果应该是 [[1,2,3],[4,6,8]] 。任何建议将不胜感激。

import numpy as np
from numpy import*


a = [array([  1,   2,   3], dtype=int16), array([4, 6, 8], 
    dtype=int16)]

【问题讨论】:

  • 为什么你甚至有一个数组列表,为什么你想要一个列表列表而不是二维数组?
  • 旁白:你真的不想做from numpy import *。它可能会导致您不想花时间被困惑的微妙问题。请改用np. 方法。

标签: python


【解决方案1】:

只需使用 Numpys tolist 函数。

np.array(a).tolist()

【讨论】:

    【解决方案2】:

    简单地说:

    x = [list(i) for i in a]
    

    输出

    [[1, 2, 3], [4, 6, 8]]
    

    【讨论】:

      猜你喜欢
      • 2016-01-06
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 2020-10-14
      • 1970-01-01
      相关资源
      最近更新 更多