如何打印不带括号的Numpy数组? [英] How to print a Numpy array without brackets?

查看:806
本文介绍了如何打印不带括号的Numpy数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将a = [1,2,3,4,5]转换为a_string = "1 2 3 4 5".实际的numpy数组很大(50000x200),因此我认为使用for loops的速度太慢.

I want to convert a = [1,2,3,4,5] into a_string = "1 2 3 4 5". The real numpy array is quite big (50000x200) so I assume using for loops is too slow.

推荐答案

您可以从字符串中使用join方法:

You can use the join method from string:

>>> a = [1,2,3,4,5]
>>> ' '.join(map(str, a))
"1 2 3 4 5"

这篇关于如何打印不带括号的Numpy数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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