pir
pir

Reputation: 5923

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,)

Upvotes: 4

Views: 12659

Answers (1)

Mathias711
Mathias711

Reputation: 6658

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

Upvotes: 6

Related Questions