floating-accuracy

Numpy dot too clever about symmetric multiplications

依然范特西╮ 提交于 2019-11-28 08:19:07
Anybody know about documentation for this behaviour? import numpy as np A = np.random.uniform(0,1,(10,5)) w = np.ones(5) Aw = A*w Sym1 = Aw.dot(Aw.T) Sym2 = (A*w).dot((A*w).T) diff = Sym1 - Sym2 diff.max() is near machine-precision non-zero , e.g. 4.4e-16. This (the discrepancy from 0) is usually fine... in a finite-precision world we should not be surprised. Moreover, I would guess that numpy is being smart about symmetric products, to save flops and ensure symmetric output... But I deal with chaotic systems, and this small discrepancy quickly becomes noticeable when debugging . So I'd like

MySQL “greater than” condition sometimes returns row with equal value

青春壹個敷衍的年華 提交于 2019-11-28 07:56:49
问题 I'm running into a baffling issue with a basic MySQL query. This is my table: id | rating 1 | 1317.17 2 | 1280.59 3 | 995.12 4 | 973.88 Now, I'm attempting to find all rows where the rating column is larger than a certain value. If I try the following query: SELECT * FROM (`users`) WHERE `rating` > '995.12' It correctly returns 2 . But, if I try SELECT * FROM (`users`) WHERE `rating` > '973.88' it returns 4 ! So it's as if it thinks the 973.88 in the table is greater than 973.88, but it doesn

How to get bc to handle numbers in scientific (aka exponential) notation?

a 夏天 提交于 2019-11-28 07:12:51
bc doesn't like numbers expressed in scientific notation (aka exponential notation). $ echo "3.1e1*2" | bc -l (standard_in) 1: parse error but I need to use it to handle a few records that are expressed in this notation. Is there a way to get bc to understand exponential notation? If not, what can I do to translate them into a format that bc will understand? Ferdinando Randisi Unfortunately, bc doesn't support scientific notation. However, it can be translated into a format that bc can handle, using extended regex as per POSIX in sed: sed -E 's/([+-]?[0-9.]+)[eE]\+?(-?)([0-9]+)/(\1*10^\2\3)/g'

Why does the value of this float change from what it was set to?

给你一囗甜甜゛ 提交于 2019-11-28 03:33:12
问题 Why is this C program giving the "wrong" output? #include<stdio.h> void main() { float f = 12345.054321; printf("%f", f); getch(); } Output: 12345.054688 But the output should be, 12345.054321 . I am using VC++ in VS2008. 回答1: It's giving the "wrong" answer simply because not all real values are representable by floats (or doubles, for that matter). What you'll get is an approximation based on the underlying encoding. In order to represent every real value, even between 1.0x10 -100 and 1.1x10

How do I set the floating point precision in Perl?

一个人想着一个人 提交于 2019-11-28 02:40:44
问题 Is there a way to set a Perl script's floating point precision (to 3 digits), without having to change it specifically for every variable? Something similar to TCL's: global tcl_precision set tcl_precision 3 回答1: There is no way to globally change this. If it is just for display purposes then use sprintf("%.3f", $value); . For mathematical purposes, use (int(($value * 1000.0) + 0.5) / 1000.0) . This would work for positive numbers. You would need to change it to work with negative numbers

How to overcome inaccuracy in Java

不打扰是莪最后的温柔 提交于 2019-11-28 02:25:34
问题 I came to know about the accuracy issues when I executed the following following program: public static void main(String args[]) { double table[][] = new double[5][4]; int i, j; for(i = 0, j = 0; i <= 90; i+= 15) { if(i == 15 || i == 75) continue; table[j][0] = i; double theta = StrictMath.toRadians((double)i); table[j][1] = StrictMath.sin(theta); table[j][2] = StrictMath.cos(theta); table[j++][3] = StrictMath.tan(theta); } System.out.println("angle#sin#cos#tan"); for(i = 0; i < table.length;

SQL Server Float data type calculation vs decimal

£可爱£侵袭症+ 提交于 2019-11-28 02:01:29
问题 In the following query declare @a float(23) declare @b float(23) declare @c float(53) set @a = 123456789012.1234 set @b = 1234567.12345678 set @c = @a * @b select @c select LTRIM(STR((@c),32,12)) declare @x decimal(16,4) declare @y decimal(16,8) declare @z decimal (32,12) set @x = 123456789012.1234 set @y = 1234567.12345678 set @z = @x * @y select @z I get answers as 1.52415693411713E+17 152415693411713020.000000000000 152415692881907790.143935926652 From the above answers the third answer is

Precision lost while using read_csv in pandas

女生的网名这么多〃 提交于 2019-11-27 23:03:28
I have files of the below format in a text file which I am trying to read into a pandas dataframe. 895|2015-4-23|19|10000|LA|0.4677978806|0.4773469340|0.4089938425|0.8224291972|0.8652525793|0.6829942860|0.5139162227| As you can see there are 10 integers after the floating point in the input file. df = pd.read_csv('mockup.txt',header=None,delimiter='|') When I try to read it into dataframe, I am not getting the last 4 integers df[5].head() 0 0.467798 1 0.258165 2 0.860384 3 0.803388 4 0.249820 Name: 5, dtype: float64 How can I get the complete precision as present in the input file? I have some

Precise sum of floating point numbers

北慕城南 提交于 2019-11-27 22:51:04
I am aware of a similar question , but I want to ask for people opinion on my algorithm to sum floating point numbers as accurately as possible with practical costs. Here is my first solution: put all numbers into a min-absolute-heap. // EDIT as told by comments below pop the 2 smallest ones. add them. put the result back into the heap. continue until there is only 1 number in the heap. This one would take O(n*logn) instead of normal O(n). Is that really worth it? The second solution comes from the characteristic of the data I'm working on. It is a huge list of positive numbers with similar

Comparing Same Float Values In C [duplicate]

末鹿安然 提交于 2019-11-27 21:54:32
问题 Possible Duplicate: strange output in comparison of float with float literal When I am trying to compare 2 same float values it doesn't print "equal values" in the following code : void main() { float a = 0.7; clrscr(); if (a < 0.7) printf("value : %f",a); else if (a == 0.7) printf("equal values"); else printf("hello"); getch(); } Thanks in advance. 回答1: While many people will tell you to always compare floating point numbers with an epsilon (and it's usually a good idea, though it should be