如何在numpy 2d数组中存储列表? [英] How can i store a list within a numpy 2d array?

查看:91
本文介绍了如何在numpy 2d数组中存储列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在numpy二维数组中存储列表?

How can i store a list within a numpy 2d array?

import numpy  
A = numpy.empty([5,5], dtype=**?**)  

这里的变量列表类型的dtype应该是什么?还是有其他方法可以实现这一点,我坚信情况会如此.

What should be the dtype for a variable list kind of thing here? or Is there a different way to implement this, which I strongly feel would be the case.

推荐答案

我认为您想要的是:

>>> input = numpy.array(range(10))
>>> data = numpy.zeros((2,2), dtype=numpy.ndarray)
>>> data[1][1] = input
>>> data
    array([[0, 0],
          [0, [0 1 2 3 4 5 6 7 8 9]]], dtype=object)

这篇关于如何在numpy 2d数组中存储列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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