All Questions

Tagged with
63 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
7votes
1answer
774views

How to avoid Numpy type conversions?

Is it possible to avoid or emit warnings for automatic Numpy type conversions from integer and 32 bit float arrays to 64 bit float arrays? My use case for this is that I'm developing a large analysis ...
user avatar
  • 2,420
4votes
0answers
112views

Is there a way to force numpy.set_printoptions to show the exact float value?

Following question 59674518, is there a way for numpy.set_printoptions to ensure the EXACT float value is displayed, without displaying trailing zeros, and without knowing the value a priori? I have ...
user avatar
  • 571
4votes
1answer
502views

Why does complex floating-point division underflow weirdly with NumPy?

Consider this code: import numpy numpy.seterr(under='warn') x1 = 1 + 1j / (1 << 533) x2 = 1 - 1j / (1 << 533) y1 = x1 * 1.1 y2 = x2 * 1.1 z1 = x1 / 1.1 z2 = x2 / 1.1 print(numpy.divide(1, ...
user avatar
  • 196k
3votes
0answers
81views

wrong result on adition of numbers larger than epsilon using numpy.float128

Considering that epsilon is the smallest number that you can add to one. I'm getting 1 instead of 1+epsilon when I perform the addition and print the result. I've implemented a getEpsilon function. I ...
user avatar
  • 441
3votes
0answers
107views

Is there a way to disable denormals in numpy? (Enabling ftz and daz flags)

I'm trying to perform a few calculations on floating point numbers that are close to the float32 min. I want the numbers to be flushed to zero when they drop below the float32 minimum instead of ...
user avatar
2votes
0answers
59views

Python numpy:How many digits does np.float64 have?

So I'm doing taylor expansion for exp(11.2). When I print all terms, I find some terms have 15 digits but some have 17 digits. I wonder why is that happening?
user avatar
2votes
1answer
243views

Numpy matrix multiplication instability across rows

I am multiplying two float64 matrices with the following values: import numpy as np # 4x5 matrix with identical columns. x = np.zeros((4, 5,), dtype=np.float64) x[1] = 1 x[3] = -3 w = np.array([1, 1,...
user avatar
  • 681
2votes
2answers
86views

python search float return wrong because of precision problem?

I want to find a float in a arry like this: arr = np.asarray([1351.1 , 1351.11, 1351.14, 1351.16, 1351.17]) index = np.searchsorted(arr, 1351.14, side="right") - 1 # return 2 But I find ...
user avatar
  • 7,635
2votes
0answers
44views

Slicing a pandas dataframe based on less or equal citerion

I bet this question has been answered a number of times but I am struggling to find a definitive solution. I need to delete dataframe rows based on a greater or equal condition. Because of float64 ...
user avatar
  • 99
2votes
0answers
100views

Is there a way for Python to read __float128 from a binary file?

I am trying to read a binary file that stores some __float128 variables from other C project using Python. I've been looking in the numpy.float128 but it seems that it is implemented in a different ...
user avatar
2votes
1answer
73views

JSON cannot handel numpy's float128 type

I need to dump numpy arrays of dtype float128 to JSON. For that purpose I wrote a custom array encoder, that properly handles arrays by calling tolist() on them. This works perfectly fine for all real ...
user avatar
  • 4,680
2votes
1answer
197views

Why is my calculation of covariance not precise

I am trying to write a function for calculating covariance matrix. I am getting very similar answer to the built in np.cov() but not exactly. There seems to be a loss of accuracy and precision. Does ...
user avatar
  • 2,453
2votes
0answers
7kviews

DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer

My code snippet is as follows: data,l = make_moons(100000) s = np.random.permutation(100000); temp1 = data[s[0:200],:] # Random Sampling of 200 columns temp2 = cdist(data,temp1) # Pairwise distance ...
user avatar
  • 683
2votes
0answers
565views

How to print scientific notation with all significant digits moved after decimal point in python

I am trying to print scientific numbers with all the significant digits after the decimal point. ` Python's scientific notation prints with one digit before the dot like 1.2345678E+03, '%E' % ...
user avatar
  • 494
2votes
3answers
1kviews

Inconsistent type conversion in python/numpy when using scalars or lists/arrays

I have a question about the strange way python/numpy performs type conversion. When I perform an arithmetic operation between a float32 and a float64 number, the lower precision is converted to ...
user avatar
  • 75
2votes
1answer
668views

numpy/pandas: test float64 arrays are equal up to significant digits

I have two pandas data frames in which I store money amounts, i.e. decimal numbers with at most 15 significant decimal digits. Since float64 has a precision of 15 significant decimal digits, this ...
user avatar
  • 6,788
2votes
0answers
3kviews

Python float types vs Decimal

I am an intern at TCD, Physics. I wrote a code to perform some data analysis on random particle packings. The code is written in Python. The code reads in columns of data from a .txt file, provided ...
user avatar
1vote
0answers
229views

How can I convert XYZ point cloud to binary mask image

I want to convert a set of point cloud (X, Y, Z) to a binary mask image using python. The problem is that these points are float and out of range of 0-255. To more specific, the points are related to ...
user avatar
1vote
0answers
39views

Benchmarking Float Precision per Operation in Numpy

I want to benchmark the error between 64-bit floats and 32 bit floats in Numpy for addition and multiplication. Unfortunately, I could not find exactly what I was looking for when searching for the ...
user avatar
  • 11
1vote
0answers
101views

Covariance matrices should be equal but are not

I'm computing covariance in two ways that I think should tie out, but they do not. Method 1: Compute the covariance matrix of a slice of an array of data Method 2: Compute the covariance matrix of the ...
user avatar
  • 11
1vote
1answer
33views

Is it possible to get reserved special numbers of double-precision binary floating-point with NumPy or some other package in Python

per wiki, Double-precision binary floating-point has Exponents range from −1022 to +1023 because exponents of −1023 (all 0s) and +1024 (all 1s) are reserved for special numbers. is it possible ...
user avatar
1vote
0answers
105views

numpy: wrong result when casting large float32 to int32

I have a numpy array of type np.float32 (actually no fraction part), and I expect it to be casted to only the integer part (2143289300), but the result below is different(2143289344), do you know why? ...
user avatar
  • 11
1vote
0answers
437views

Can I use Python's Decimal type with NumPy?

I'm doing some calculations with Python3 and NumPy using float64 and sometimes, when I change my formulas a little (but mathematically equivalent), then I get slightly different results. I know that ...
user avatar
  • 1,317
1vote
0answers
519views

Floats subtraction / addition - calculate loss of precision

I am trying to wrap my mind around floating-point arithmetics and related loss of precision. I do understand that I can lose a lot of precision when I perform addition of big and small numbers (due to ...
user avatar
1vote
0answers
272views

Python+numpy: a lucky floating point case?

I'm inverting a very simple matrix, and I stumbled in something which I don't understand. EDIT: In the original post I forgot to take care of the fact that numpy defaults to float64, hence the ...
user avatar
1vote
0answers
4kviews

RuntimeWarning: invalid value encountered in double_scalars

Steps of the algorithms: 1- Initialize with P and Q 2- the main process of Algorithm is started as the first for (loop) becomes to begin. This is the program that I wrote for above steps: #!/usr/...
user avatar
  • 171
1vote
3answers
1kviews

Generate array of floats within possible MAX and MIN

I'm trying to generate floats however not within [0-1) but sys.float_info.max and sys.float_info.min. Unfortunately Python's random and Numpy random work as this way a + (b-a) * random() But random()...
user avatar
0votes
0answers
37views

Fast inverse square root in python on float32

I have done some checks for the fast inverse square root method in python (jupyterlab using python version 3.8.8) and for some reason then I've come to the conclusion that I must either be doing ...
user avatar
  • 1
0votes
0answers
70views

how to convert pandas dataframe into a numpy array with floats

I cannot convert it using the following commands import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt df = pd.read_csv('sample.csv') print(df.head()) ...
user avatar
0votes
1answer
32views

Why does cholesky factorization fail for pascal matrices of big size?

I want to perform cholesky factorization for pascal matrix of size 50. The values become too large so scipy.linalg.pascal returns matrix of object type. A_scipy = scipy.linalg.pascal(50) A_scipy.dtype ...
user avatar
  • 455
0votes
0answers
24views

set_print_options failes when transfering scientific notation to float with specified precision in numpy

Ok I have tried hundred things, I went through old questions and I read the numpy.set_print_options but it won't work. So I have an array which looks something like this when printed: array([[2....
user avatar
0votes
0answers
22views

numpy seterrcall, how to flag the object that caused the flouting point error?

I have a function that loops through a list of objects, each these objects are associated with numpy functions (add, multiple, divide). When calling the object with arguments, the associated numpy ...
user avatar
0votes
1answer
168views

How can .0 decimals be included when working with numpy floats

I have a numpy array containing mostly whole numbers and floats. The way I understand it, arrays are always stored as floats, and so the integers are stored as <number>.0. I want to work with ...
user avatar
0votes
0answers
19views

How to find the bit value (precision) of a trained CNN/ANN model?

I have CNN model (ONNX) taken from Github repository for general purpose classification. I want to find if the model weights are trained with single precision values (32 bit) or half precision values (...
user avatar
0votes
0answers
46views

Python, compare if a Float is close to an Integer

I'm coding a program to analyse sentiments in Tweets. I want to perform a test where I have a dataset of Tweets like this : label,text 0, blabla 1, blablabla 0, blablablabla where label is ...
user avatar
  • 626
0votes
0answers
103views

numpy.float64' object cannot be interpreted as an integer

I have some problems running this code on the hillslope diffuson equation. I am not an expertise in python code! Even if I correcte some other problems the code return me again the problem about '...
user avatar
0votes
0answers
74views

How to efficiently encode a 1D float32 numpy array in json without loss of precision?

I have a 1D numpy array of type float32. I want to create a JSON file which efficiently encodes the numpy array without degrading the precision. Since JSON is encoded in characters and not numbers, ...
user avatar
0votes
1answer
285views

python numpy.single gives different result when using out parameter

I am trying to cast from a double precision array to single precision. To optimize on space I tried using the out argument so that numpy doesn't allocate additional space. However the results seem ...
user avatar
  • 1,838
0votes
0answers
66views

Float64 granularity: what is the longest possible line?

The IEEE defines float64's range from -2.23e-308 to +1.8e+308. But what is the granularity implied by this range? That is, what is the maximum number of nonzero increments we can make from the minimum ...
user avatar
0votes
0answers
106views

Precision loss in numpy float32 conversion

I'm experiencing a weird behaviour when converting a scalar or array to numpy.float32. I suspect it's linked to the precision limit but can't exactly pinpoint where it's coming from. Here is an ...
user avatar
0votes
1answer
132views

How to read multiple data types from memoryview in Python?

I am reading sensor data, which has 6 columns, first four are 32 bit floats, and the last two are unsigned integers. Here is how it is converted into a numpy array: data = np.frombuffer(sensor_data....
user avatar
0votes
1answer
413views

Constrain numpy to automatically convert integers to floating-point numbers (python 3.7)

I have just made the following mistake: a = np.array([0,3,2, 1]) a[0] = .001 I was expecting 0 to be replaced by .001 (and the dtype of my numpy array to automatically switch from int to float). ...
user avatar
0votes
1answer
249views

Python iterate over a float array or list

I have a Pandas dataframe and i Need to create a function to a specific column in it which has only Floating Point values. i can retrieve the column and convert it to list or Array. But Once i use for ...
user avatar
0votes
3answers
717views

Conversion from float (native float or numpy.float64) to integer not working

I have a dataframe thats loaded with floats and NaNs. I need to convert all the decimals/floats to integers. I checked that all types are numpy.float64 but my conversion to integer does not work. This ...
user avatar
0votes
0answers
445views

Check if byte string represents float or int

I have some byte strings and I don't know if they are integers or floats. Lets create some example data: import numpy as np arr_int = np.array([17, int(1e10), 34567]) arr_float = np.array([17.17,...
user avatar
  • 4,026
0votes
2answers
599views

Checking if float value is in numpy array

I am trying to find out if a value is in numpy array. The array is generated using linspace method and gets float64 type. My value is float type. As the outcome "value in array" check always returns ...
user avatar
  • 99
0votes
1answer
202views

python (numpy, float, or decimal) - set min amd max decimal places in string representation

In Python (either in regular float, numpy, or decimal), is there a way to set both a min and max decimal places when getting the string representation? Say I want min decimal places to be 2, and max ...
user avatar
  • 1,058
0votes
1answer
181views

How can I compare two arrays with different sizes but with some floats that are approximate? [Python3]

How can I compare two arrays with different sizes but with some floats that are approximate? For example: # I have two arrays a = np.array( [-2.83, -2.54, ..., 0.05, ..., 2.54, 2.83] ) b = np.array( [...
user avatar
0votes
0answers
86views

"'type' object is not a subscriptable error" in Python

import pyglet class CarMap: def __init__(self): self.in_map = [341, 161, 452, 121, 567, 123, 650, 160, 678, 241, 613, 340, 654, 467, 611, 508, 506, 514, 416, 437, 289, 401, 207,...
user avatar
  • 33
0votes
0answers
123views

How to make sure a probability distribution add up to exactly 1.0 in python numpy?

I am using Latent Dirichlet Allocation function in sklearn: http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html The output is a 2d numpy array of ...
user avatar

15 30 50 per page