Loading a numpy array that has been saved using savetxt with a format option

StatsSorceress

I've seen how to save a numpy array with a format option (here). I saved my numpy array like this:

np.savetxt('my_file.txt', results, fmt='%1.4f', delimiter=",")

It looks fine:

0.0050,0.0100,0.0150,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0150,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0200,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0150,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0100,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0050,0.0100,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0150,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0100,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0100,0.0000,0.0000,0.0050,0.0000,0.0150
0.0050,0.0100,0.0100,0.0000,0.0000,0.0050,0.0000,0.0150

Now when I try to load it I get an error:

pl_sioux = np.loadtxt("my_file.txt")

Traceback (most recent call last):
  File "rfresults.py", line 3, in <module>
    pl_sioux = np.loadtxt("rf_pl_Sioux.txt") #, dtype='f')
  File "/user/pkgs/anaconda2/lib/python2.7/site-packages/numpy/lib/npyio.py", line 1092, in loadtxt
    for x in read_data(_loadtxt_chunksize):
  File "/user/pkgs/anaconda2/lib/python2.7/site-packages/numpy/lib/npyio.py", line 1019, in read_data
    items = [conv(val) for (conv, val) in zip(converters, vals)]
  File "/user/pkgs/anaconda2/lib/python2.7/site-packages/numpy/lib/npyio.py", line 738, in floatconv
    return float(x)
ValueError: invalid literal for float(): 0.0050,0.0100,0.0150,0.0000,0.0000,0.0050,0.0000,0.0150

I tried this, to math the fmt option:

loaded_file = np.loadtxt("my_file.txt", dtype='f')

but got the same error.

How can I load my numpy array?

DYZ

The default delimiter value is a whitespace. You have to provide the value of the actual delimiter:

np.loadtxt("my_file.txt", delimiter=",")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to format in numpy savetxt such that zeros are saved only as "0"

Write numpy structured array using savetxt

Finding shape of saved numpy array (.npy or .npz) without loading into memory

How to reintroduce "no prompt to save" option in IDLE if file has never been saved

Detecting if an <option> has been selected in <select> using CSS

Saving data using numpy.savetxt

value error when using numpy.savetxt

numpy savetxt fails when using file handler

Using newline as a separator with numpy.savetxt not working

IO error in savetxt while using numpy

Which fmt option in numpy.savetxt keeps infinite integer precision?

Python: Saving / loading large array using numpy

Is it possible to FORMAT an external hard disk that has been encrypted using Storagecrypt?

Validate() returns false but it has been saved in the database

Determine if an Excel workbook has ever been saved?

No entry has been saved to database in ruby on rails?

How to check if an instance update has been saved?

Know if an element has been saved or updated Nhibernate

python numpy.savetxt header has extra character #

Source code prompts data has been saved but no data appears in table. Using pyCharm and Postgres for development

How to use numpy.savetxt with a structured array that contains an array

Loading numpy structured array saved in python3 in python2

Using numpy 'module' object has no attribute 'array'

Format RGB to Hex using Numpy Array Operations

How to parse object array that has been stringified using backslashes

How to determine which element has been clicked using a for statement and array

Numpy savetxt saves 1D array as column

How to have two leading blanks using savetxt in Numpy

How to change the auto rounding of floats in a numpy array after the array has been divided by a constant?