I am getting a very weird and unexpected ERROR from python-numpy
I am working with the following libraries:
import os, glob, string, math, csv, json
import datetime as dt
import numpy as np
import scipy as sci
import pandas as pd
import matplotlib.pyplot as plt
import feedparser as fp
import cPickle as pickle
import networkx as nx
from urllib2 import urlopen
import statsmodels.formula.api as sm
import patsy
The following code:
n,k = 2643605051, 648128.068241
print n,type(n)
print k, type(k)
nkvar = (k + 1)*(n + 2)/( (n+2) * (n+1)**2 )
print nkvar
n = np.int64(n)
k = np.float64(k)
print n,type(n)
print k, type(k)
nkvar = (k + 1)*(n + 2)/( (n+2) * (n+1)**2 )
print nkvar
Yields:
2643605051 <type 'int'>
648128.068241 <type 'float'>
9.27402694708e-14
2643605051 <type 'numpy.int64'>
648128.068241 <type 'numpy.float64'>
-0.00383719008751
The second answer is OBVIOUSLY wrong! Could someone please help me understand what is going on?
n,k = 2643605051, 648128.068241 print n,type(n) print k, type(k) nkvar = (k + 1)*(n + 2)/( (n+2) * (n+1)**2 ) print nkvar n = np.int64(n) k = np.float64(k) print n,type(n) print k, type(k) nkvar = (k + 1)*(n + 2)/( (n+2) * (n+1)**2 ) print nkvarwhich yields:2643605051 <type 'int'> 648128.068241 <type 'float'> 9.27402694708e-14 2643605051 <type 'numpy.int64'> 648128.068241 <type 'numpy.float64'> -0.00383719008751int64is 64-bit. Operations on it are restricted to 64 bits.intproduces arbitrary-precisionlongs if the result doesn't fit into anint.