Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a number float64?

I have a number

e.g.

a = 1.22373

type(a) is float

Like wise I want to find if a number is

float64 

or not.

How I will find using Python or NumPy?

like image 822
sam Avatar asked Jan 21 '14 09:01

sam


People also ask

Is a float64 a double?

Float64 is just a type alias to Double .

What is float 32 and float64?

float32 is a 32 bit number - float64 uses 64 bits. That means that float64's take up twice as much memory - and doing operations on them may be a lot slower in some machine architectures. However, float64's can represent numbers much more accurately than 32 bit floats. They also allow much larger numbers to be stored.

Can a float 64 be negative?

Range. A variable of type float64 can store decimal numbers ranging from 2.2E-308 to 1.7E+308. This applies to negative and positive numbers.


Video Answer


2 Answers

Use isinstance:

>>> f = numpy.float64(1.4)
>>> isinstance(f, numpy.float64)
True
>>> isinstance(f, float)
True

numpy.float64 is inherited from python native float type. That because it is both float and float64 (@Bakuriu thx for pointing out). But if you will check python float instance variable for float64 type you will get False in result:

>>> f = 1.4
>>> isinstance(f, numpy.float64)
False
>>> isinstance(f, float)
True
like image 177
ndpu Avatar answered Oct 11 '22 12:10

ndpu


I find this is the most readable method for checking Numpy number types

import numpy as np
npNum = np.array([2.0]) 

if npNum.dtype == np.float64:
    print('This array is a Float64')

# or if checking for multiple number types:
if npNum.dtype in [
    np.float32, np.float64, 
    np.int8, np.uint8, 
    np.int16, np.uint16, 
    np.int32, np.uint32, 
    np.int64, np.uint64
    ]:

    print('This array is either a float64, float32 or an integer')
like image 32
DougR Avatar answered Oct 11 '22 12:10

DougR