一维数组的numpy的列表,二维数组 [英] Numpy list of 1D Arrays to 2D Array

查看:360
本文介绍了一维数组的numpy的列表,二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含通过 numpy.save 腌2D numpy的阵列大名单的文件。我想读每个文件的第一列,并创建一个新的二维数组。

I have a large list files that contain 2D numpy arrays pickled through numpy.save. I am trying to read the first column of each file and create a new 2D array.

我目前正在读取使用 numpy.load 每列以 MMAP 。在一维数组现在在列表中。

I currently read each column using numpy.load with a mmap. The 1D arrays are now in a list.

col_list = []
for f in file_list:
    Temp = np.load(f,mmap_mode='r')
    col_list.append(Temp[:,0])

我怎么能转换成这一个二维数组?

How can I convert this into a 2D array?

推荐答案

您只需调用 np.array 一维数组的名单上。

You can just call np.array on the list of 1D arrays.

>>> import numpy as np
>>> arrs = [np.array([1,2,3]), np.array([4,5,6]), np.array([7,8,9])]
>>> arrs
[array([1, 2, 3]), array([4, 5, 6]), array([7, 8, 9])]
>>> arr2d = np.array(arrs)
>>> arr2d.shape
(3, 3)
>>> arr2d
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

这篇关于一维数组的numpy的列表,二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆