Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1D numpy array to float

I want to convert a 1D numpy array to a simple float (no array). How is that done? Here is my current code with the variable 'acc'.

print type(acc)
print acc.shape

>>> <type 'numpy.ndarray'>
>>> (1,)
like image 761
pir Avatar asked Oct 26 '25 10:10

pir


1 Answers

Can't you just do:

float(acc)

To make it a float? Seems to be working here:

a = np.array([1])
print a.shape
print type(a)
print float(a)

yields

(1,)
<type 'numpy.ndarray'>
1.0
like image 50
Mathias711 Avatar answered Oct 29 '25 00:10

Mathias711