我可以在打印声明中摆脱这个“ b”字符​​吗? [英] Can I get rid of this 'b' character in my print statement?

查看:121
本文介绍了我可以在打印声明中摆脱这个“ b”字符​​吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 b 这个字符是什么以及为什么它出现。我还想知道在打印数组时是否可以摆脱它?

I'm wondering what this b charcter is and why it's appearing. I'm also wondering if I can get rid of it while printing the array?

这是我的示例:

arr1 = np.array(['1', '2'], dtype = 'c')
print("array:", arr1, "and its dtype is: ", arr1.dtype)

这是输出:

array: [b'1' b'2'] and its dtype is:  |S1


推荐答案

这意味着字节字面量:

https://docs.python.org/2 /whatsnew/2.6.html?highlight=string%20byte%20literal#pep-3112-byte-literals

要摆脱它,您可以尝试输出为字符串而不是数组对象

As to getting rid of it you might try outputting as string rather than as an array object

例如:

s="["
for x in arr1:
    s += x.decode('utf-8')   
s+= "]"

print ("array: ", s , " and it's dtype is: ", arr1.dtype");

这篇关于我可以在打印声明中摆脱这个“ b”字符​​吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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