Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numpy fromstring behavior (v1.12.1,v1.13.1) #9484

Closed
tonymonk007 opened this issue Jul 28, 2017 · 4 comments
Closed

numpy fromstring behavior (v1.12.1,v1.13.1) #9484

tonymonk007 opened this issue Jul 28, 2017 · 4 comments

Comments

@tonymonk007
Copy link

Hi,

I am trying to use np.fromstring to read Hex code into ascii array. However, I get the following result when I expect only 170. Does anybody happen to know where the number "194" is from?

>>>import numpy as np
>>>np.fromstring('\xaa',np.uint8)
array([194, 170], dtype=uint8)

This is the example from the document.

>>> np.fromstring('\x01\x02\x03\x04\x05', dtype=np.uint8, count=3)
array([1, 2, 3], dtype=uint8)

Thanks

@jaimefrio
Copy link
Member

It works properly (returns 170 only) with 1.11.1 on Linux, which is what I have available right now.

@tonymonk007
Copy link
Author

I tried both 1.12 and 1.13 in Linux. They all give [194,170] instead of 170.

@tonymonk007 tonymonk007 changed the title numpy fromstring behavior numpy fromstring behavior (v1.2.1,v1.3.1) Jul 28, 2017
@tonymonk007 tonymonk007 changed the title numpy fromstring behavior (v1.2.1,v1.3.1) numpy fromstring behavior (v1.12.1,v1.13.1) Jul 28, 2017
@eric-wieser
Copy link
Member

eric-wieser commented Jul 28, 2017

This is python 3, right? There, '\xaa' is a unicode object, so is being utf8-encoded in order to obtain bytes

This doesn't happen on python 2, because quotes create bytes objects

@eric-wieser
Copy link
Member

IMO, np.fromstring(unicode) should just throw an error - we should have been using y, not s, in PyArg_ParseTupleAndKeywords

Can we do that, or do we need to deprecate it first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants