I have some data files that contain boolean output from Fortran code:
write(23,'(L2)') data
therefore, a portion of the file will look like this:
F F T F ...
I would like to read this file in Python with numpy.asarray() function, because it is easy to convert data this way, e.g.:
data = asarray(f.readline().split(),'bool')
However, no matter what data it is, Python always returns an array with all 'True's.
I have also tried to write as 'False False True False ...' or '0 0 1 0 ...', and they both did not work.
I would like to know if there is a way to use asarray() to achieve this? or any other suggestions that can convert boolean data without using loops?
If you can read in the data as an array of "T" and "F" strings then you could do the following:
>>> a = np.array(["T", "F", "T"])
>>> a == "T"
array([ True, False, True], dtype=bool)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With