numpy:通过数组比较创建向量不起作用 [英] Numpy: Creating a Vector through Array Comparison is NOT working

查看:74
本文介绍了numpy:通过数组比较创建向量不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下面的IPython(Python 3)快照所示,我希望最后看到一个布尔值数组.但是,我看到只有1个布尔值返回.

As shown in the IPython (Python 3) snapshot below I expect to see an array of Boolean values printed in the end. However, I see ONLY 1 Boolean value returned.

  1. 无法确定原因?
  2. 每个字符之前的字符"b"是什么 第一个打印语句中的值表示什么?我用错了吗 我的numpy.getfromtxt()命令中的dtype = numpy.string _?
  1. Unable to identify why?
  2. What does the character 'b' before every value in the first print statement denote? Am I using the wrong dtype=numpy.string_ in my numpy.getfromtxt() command?

推荐答案

Python区分unicode字符串和ASCII字节.在Python3中,默认值是字符串"是unicode.

Python has the distinction between unicode strings and ASCII bytes. In Python3, the default is that "strings" are unicode.

以字符串"为前缀的 b 表示解释器将其视为字节.

The b prefixing the "strings", indicate that the interpreter considers these to be bytes.

为进行比较,您还需要将其与字节进行比较,即

For the comparison, you need to compare it to bytes as well, i.e.,

... == b"1984"

然后numpy将理解它应该在相同类型的元素上执行广播.

and then numpy will understand that it should perform broadcasting on same-type elements.

这篇关于numpy:通过数组比较创建向量不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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