欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

「Python」Numpy equivalent of MATLAB's cell array

程序员文章站 2022-05-11 14:46:43
转自*。备忘用。 Question I want to create a MATLAB like cell array in Numpy. How can I accomplish this? Answer Matlab cell arrays are most simila ......

转自*。备忘用。

question

i want to create a matlab-like cell array in numpy. how can i accomplish this?

answer

matlab cell arrays are most similar to python lists, since they can hold any object - but scipy.io.loadmat imports them as numpy object arrays - which is an array with dtype=object.

to be honest though you are just as well off using python lists - if you are holding general objects you will loose almost all of the advantages of numpy arrays (which are designed to hold a sequence of values which each take the same amount of memory).