Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only one value in file, numpy.loadtxt() just returns the value instead of array?

Tags:

python

numpy

When only one value in file, numpy.loadtxt() just returns the value instead of array, how to avoid?

Thank you in advance!

e.g. there's only 12345 in a file

12345.6

numpy.loadtxt() returns

12345.6

instead of

array([12345.6])
like image 809
bayesrule Avatar asked Oct 27 '25 07:10

bayesrule


1 Answers

Use the ndmin parameter of numpy.loadtxt. Set it to 1, and you will always have an array with at least one dimension.

like image 66
John Zwinck Avatar answered Oct 29 '25 21:10

John Zwinck