scientific-computing

Reshaping a pandas DataFrame into stacked/record/database/long format

此生再无相见时 提交于 2019-12-10 16:39:48
问题 What is the best way to convert a pandas DataFrame from wide format into stacked/record/database/long format? Here's a small code example: Wide format: date hour1 hour2 hour3 hour4 2012-12-31 9.18 -0.10 -7.00 -64.92 2012-12-30 13.91 0.09 -0.96 0.08 2012-12-29 12.97 11.82 11.65 10.20 2012-12-28 22.01 16.04 15.68 11.67 2012-12-27 11.44 0.07 -19.97 -67.98 ... Stacked/record/database/long format (needed): date hour price 2012-12-31 00:00:00 hour1 9.18 2012-12-31 00:00:00 hour2 -0.1 2012-12-31 00

Pandas rolling window appears to introduce offset to rolled data

不羁的心 提交于 2019-12-10 09:33:18
问题 I am looking to 'smooth' regularly-sampled 30-sec time series data using the pandas rolling_window function, with a window type other than boxcar - ideally hamming . However, so far all windows which I have tried to apply, over varying window lengths from 2 to 100, appear to offset the smoothed data to lower values, e.g.: Plot of raw data (light blue) and data run through pd.rolling_window(data,2,'hamming') . Clearly, the quantity of offset varies through time. This result isn't what I would

Nonlinear e^(-x) regression using scipy, python, numpy

不羁岁月 提交于 2019-12-10 03:45:56
问题 The code below is giving me a flat line for the line of best fit rather than a nice curve along the model of e^(-x) that would fit the data. Can anyone show me how to fix the code below so that it fits my data? import numpy as np import matplotlib.pyplot as plt import scipy.optimize def _eNegX_(p,x): x0,y0,c,k=p y = (c * np.exp(-k*(x-x0))) + y0 return y def _eNegX_residuals(p,x,y): return y - _eNegX_(p,x) def Get_eNegX_Coefficients(x,y): print 'x is: ',x print 'y is: ',y # Calculate p_guess

Tracing Python warnings/errors to a line number in numpy and scipy

笑着哭i 提交于 2019-12-10 01:47:54
问题 I am getting the error: Warning: invalid value encountered in log From Python and I believe the error is thrown by numpy (using version 1.5.0). However, since I am calling the "log" function in several places, I'm not sure where the error is coming from. Is there a way to get numpy to print the line number that generated this error? I assume the warning is caused by taking the log of a number that is small enough to be rounded to 0 or smaller (negative). Is that right? What is the usual

best lib for vector array in c++

倖福魔咒の 提交于 2019-12-09 13:42:07
问题 I have to do calculation on array of 1,2,3...9 dimensional vectors, and the number of those vectors varies significantly (say from 100 to up to couple of millions). Of course, it would be great if the data container can be easily decomposed to enable parallel algorithms. I came across blitz++(almost impossible to compile for me), but are there any other fast libs that manipulate array of vector data? Is boost::fusion worth a look? Furthermore, vtk's vtkDoubleArray seems nice, but vtk is lib

MATLAB: Block matrix multiplying without loops

蹲街弑〆低调 提交于 2019-12-08 01:48:28
问题 I have a block matrix [A B C...] and a matrix D (all 2-dimensional). D has dimensions y-by-y, and A, B, C , etc are each z-by-y. Basically, what I want to compute is the matrix [D*(A'); D*(B'); D*(C');...] , where X ' refers to the transpose of X . However, I want to accomplish this without loops for speed considerations. I have been playing with the reshape command for several hours now, and I know how to use it in other cases, but this use case is different from the other ones and I cannot

Catch Floating Point Exceptions using a compiler option with C [closed]

柔情痞子 提交于 2019-12-07 14:26:43
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . Gfortran has the handy -ffpe-trap compiler option, but no similar option is available for gcc . I am vaguely aware that they handle exceptions differently, but not enough to know why one can die from FPEs just by enabling a compiler flag, but the other requires including extra code to turn

Using scipy gaussian kernel density estimation to calculate CDF inverse

て烟熏妆下的殇ゞ 提交于 2019-12-07 13:04:49
问题 The gaussian_kde function in scipy.stats has a function evaluate that can returns the value of the PDF of an input point. I'm trying to use gaussian_kde to estimate the inverse CDF. The motivation is for generating Monte Carlo realizations of some input data whose statistical distribution is numerically estimated using KDE. Is there a method bound to gaussian_kde that serves this purpose? The example below shows how this should work for the case of a Gaussian distribution. First I show how to

Efficient ways to write a large NumPy array to a file

南笙酒味 提交于 2019-12-07 04:37:06
问题 I've currently got a project running on PiCloud that involves multiple iterations of an ODE Solver. Each iteration produces a NumPy array of about 30 rows and 1500 columns, with each iterations being appended to the bottom of the array of the previous results. Normally, I'd just let these fairly big arrays be returned by the function, hold them in memory and deal with them all at one. Except PiCloud has a fairly restrictive cap on the size of the data that can be out and out returned by a

What kind of work benifits from OpenCL

跟風遠走 提交于 2019-12-07 03:38:57
问题 First of all: I am well aware that OpenCL does not magically make everything faster I am well aware that OpenCL has limitations So now to my question, i am used to do different scientific calculations using programming. Some of the things i work with is pretty intense in regards to the complexity and number of calculations. SO i was wondering, maybe i could speed things up bu using OpenCL. So, what i would love to hear from you all is answers to some of the following [bonus for links]: *What