0

I am facing some trouble with the numpy genfromtxt fonction. It seems that the function is removing slashes from strings.

Here is a simplified version of my code that shows the problem.

Here, I create some dtype with a slash (/) in the string name.

import numpy as np
#Creating my_dtype 
my_dtype = np.dtype([('test/slash','int')]) 

Without using the fonction genfromtxt, it is working.

print(my_dtype)                                     
>>> [('test/slash', '<i8')]

Then, I try to extract data from a file, which for the example only contain one value. So it is a single row, single column file.

#Reading data from file
data = np.genfromtxt('test_data',dtype=my_dtype)    

And here is the apperance of the behaviour that I don't understand.

print(my_dtype)
>>> [('testslash', '<i8')]

where I expect the slash in the name.

>>> [('test/slash', '<i8')]

It is the same for the data dtype.

print(data.dtype)
>>> [('testslash', '<i8')]

I tried this with python and python3 in Ubuntu 16.04 environment.

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
  • The default behavior is to 'cleanup' the field names so they work as recarray attributes. You can change that somewhat with parameters. But there's a SO question that discusses some bug in this control. – hpaulj May 13 '16 at 11:05
  • See http://stackoverflow.com/a/35237284/901925 – hpaulj May 13 '16 at 11:12

0 Answers0