【问题标题】:Make Array from an Array in python [closed]从python中的数组制作数组[关闭]
【发布时间】:2018-05-11 12:13:01
【问题描述】:

我遇到了从我的大数据中拆分数组的问题。所以我有一个数据数组,其形状为 (86594,12)。

data=([1,2,3,4,5,6,7,8..,12],[13,14,15,16,17,18...24],...[86583,86584, ...86594])

我想拆分它,以便我可以从数据中创建一个新数组。如果新数组的形状为 (10,12),那么我将把该数组放入 8659。 请告诉我如何在python中做到这一点? 我的预期结果将是 8659 个形状为 (10,12) 的数组,所以不在 (86594,12) 的整个数据数组中

【问题讨论】:

  • 您的预期输出是什么?
  • 你想flatten the list 吗?
  • @sachindubey 我的预期结果是我有 8659 个形状为 (10,12) 的数组,所以不是在整个数据中,而是 (86594,12) 的数组
  • @Abhijeetk431 我不想,我想将形状为 (86594,12) 的数据数组拆分为形状为 (10,12) 的 8659 个数组。跨度>
  • 您希望在创建 (8659, 10, 12) 列表后的最后 (4, 12) 个元素会发生什么?

标签: python arrays


【解决方案1】:

也许你可以使用一些 numpy 方法,比如np.reshape

 >>> data = np.array([1,2,3,4,5,6,7,8..,12],[13,14,15,16,17,18...24],...[86583,86584, ...86594])
 >>> np.reshape(data, (10,12)) # C-like index ordering

【讨论】:

  • np.arange() 不适用于列表。您的意思可能是np.asarray()np.array()stackoverflow.com/questions/14415741/… 但即便如此 np.reshape() 也会抛出错误,因为 86594 不能被 10 整除。
  • 我的错,我的意思是数组,如果他添加缺少的列表,那么 reshape 会起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-21
  • 2021-01-31
  • 1970-01-01
  • 2013-11-07
  • 2021-11-27
  • 1970-01-01
  • 2019-08-15
相关资源
最近更新 更多