【问题标题】:populate a numpy array with a normal array用普通数组填充一个 numpy 数组
【发布时间】:2013-04-22 17:02:51
【问题描述】:
connum = np.empty((160,160))
confidence = [2142,213124,23123,34324,4545,56634,343,45435,12312,4543,343]

我有列表confidence 和numpy 数组connum 我如何用列表confidence 的元素填充empy numpy 数组

【问题讨论】:

  • 你不想numpy.array(confidence)
  • 如果你想将一维列表转换为二维数组,你可以这样做:connum = np.array(confidence).reshape(160,160)
  • confidence11 元素,但 connum160*160 = 25600 元素。你想如何将你的 11 个元素分配到大数组中?
  • 它的大小不正确,向您展示我的25600confidence 元素有什么意义?
  • 为什么不创建一个最小的示例,将connum 的大小调整为confidence 列表的大小?

标签: python list numpy


【解决方案1】:

如果置信度是一个包含 25600 个元素的列表,只需执行以下操作:

connum = np.array(confidence).reshape((160,160))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 2020-11-05
    • 2017-10-24
    • 2017-09-18
    • 2016-11-06
    相关资源
    最近更新 更多