在python 3中将numpy数组列表转换为字符串时出现椭圆 [英] Ellipses when converting list of numpy arrays to string in python 3

查看:97
本文介绍了在python 3中将numpy数组列表转换为字符串时出现椭圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个numpy数组的列表.我想将数组列表转换为字符串.这样就可以得到一长串的数组,例如'[stuff],[stuff2]'等.每个数组都有192个元素.如果列表具有5个或更少的数组,则在执行str(myList)时可以进行转换.如果它有6个数组,我会返回带有省略号的截断数组.为什么是这样?我该如何阻止它?

I have a list of numpy arrays. I want to convert the list of arrays to a string. So that there will be a long string of arrays like '[ stuff ], [ stuff2 ]', etc. Each array has 192 elements. Conversion works when I do str(myList) if the list has 5 arrays or less. If it has 6 arrays, I get back truncated arrays with ellipses. Why is this? How can I stop it?.

我已经检查了数组本身,实际上它们不包含椭圆,它们包含正确的值.

I have examined the arrays themselves and they do not in fact contain ellipses, they contain the correct values.

我进一步研究了它,如果我做类似str(myList [0:5])的事情,它可以在前5个数组上工作,但是第6个数组总是变为椭圆形.请注意,在打印到屏幕上时,这也不只是椭圆形,我还要保存此变量,当我查看保存的文本时,它会带有椭圆形.

I further looked into it and if I do something like str(myList[0:5]) it works on the first 5 arrays, but that 6th array always goes to ellipses. Note that this is not just ellipses when printing to screen either, I'm saving this variable and when I look at the saved text it has the ellipses.

推荐答案

快速浏览,唯一的方法是使用numpy.set_printoptions:

From a quick look, the only way is to use numpy.set_printoptions:

import numpy as np

a = np.random.randint(5, size=(6, 192))
s1 = str(a)
np.set_printoptions(threshold = np.prod(a.shape))
s2 = str(a)

print('...' in s1)
print('...' in s2)

给予

True
False

在我的Ubuntu 14.04系统,Python 2.7,Numpy 1.8.2

on my Ubuntu 14.04 system, Python 2.7, Numpy 1.8.2

更改默认值后,我会将其恢复为1000,并且在我的 意见,函数numpy.array2string应该有一个阈值 论点.

I would restore the default to 1000 after changing it, and, in my opinion, the function numpy.array2string should have a threshold argument.

这篇关于在python 3中将numpy数组列表转换为字符串时出现椭圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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