scientific-computing

Return transformed nmatrix array with fftw3

别来无恙 提交于 2019-12-13 03:39:31
问题 I am creating a ruby wrapper for the fftw3 library for the Scientific Ruby Foundation which uses nmatrix objects instead of regular ruby arrays. I have a curious problem in returning the transformed array in that I am not sure how to do this so I can check the transform has been computed correctly against octave or (something like this) in my specs I have an idea that I might be best to cast the output array out which is an fftw_complex type to a VALUE to pass it to the nmatrix object before

Python runtime: recompiling and reusing C library

时光怂恿深爱的人放手 提交于 2019-12-12 14:33:11
问题 I am developing a tool for some numerical analysis of user-defined functions. The idea is to make a convenient UI in Python, where user can enter C function, then press a button - and receive some output data. Computations can take minutes or hours, so Numpy-only performance is not acceptable. I have tried the following approach: the Python-based UI calls gcc, compiles dll from user functions that is than used by my core C-based algorithms in Cython wrappings. It works, but since there is no

Scientific Fortran Compile Error

安稳与你 提交于 2019-12-12 12:10:40
问题 I'm working on scientific modelling program and have yet to get my program to even compile. I haven't touched the code which my professor insists previously worked, only the makefile. After many attempts, the furthest I've gotten was this error: Error on line 1112: Declaration error for xxmf: adjustable dimension on non-argument upcase: intrpl: splin: mtrnpr: My Professor insists that it's merely a compiling problem and that there should be some option involving global variables that I can

multinomial pmf in python scipy/numpy

拟墨画扇 提交于 2019-12-12 08:25:24
问题 Is there a built-in function in scipy/numpy for getting the PMF of a Multinomial? I'm not sure if binom generalizes in the correct way, e.g. # Attempt to define multinomial with n = 10, p = [0.1, 0.1, 0.8] rv = scipy.stats.binom(10, [0.1, 0.1, 0.8]) # Score the outcome 4, 4, 2 rv.pmf([4, 4, 2]) What is the correct way to do this? thanks. 回答1: There's no built-in function that I know of, and the binomial probabilities do not generalize (you need to normalise over a different set of possible

integers or floating point in situations when either would do?

佐手、 提交于 2019-12-11 19:27:44
问题 Moving a discussion on relative merits of integers and floats into a separate question. Here it is: what is your preference between an integer type or a floating point type in situations that are neither inherently integral nor inherently floating point? For example, when developing geometric engine for a well-conntrolled range of scales would you prefer integer coordinates in the smallest feasible units or float/double coordinates? 回答1: Some reasons to prefer floating-point are: When you

How to calculate the generalized inverse of a Sparse Matrix in scipy

我与影子孤独终老i 提交于 2019-12-11 11:37:55
问题 I have a sparse matrix W, when I use linalg.pinv(W) , it throws some errors: Traceback (most recent call last): File "/Users/ad9075/PycharmProjects/bednmf/test.py", line 14, in testNmfRun self.factor = factorization(self.V) File "/Users/ad9075/PycharmProjects/bednmf/nmf.py", line 18, in factorization W_trans = linalg.pinv(W) File "/Library/Python/2.7/site-packages/scipy/linalg/basic.py", line 540, in pinv b = np.identity(a.shape[0], dtype=a.dtype) IndexError: tuple index out of range` But

Runge Kutta 4 and pendulum simulation in python

放肆的年华 提交于 2019-12-11 07:49:15
问题 I am trying to make a python program which plot pendulum swings using runge kutta 4. The equation I have is angular accelartion = -(m*g*r/I) * np.sin(y) . Please find my code. I am quite new to python. import numpy as np import matplotlib.pyplot as plt m = 3.0 g = 9.8 r = 2.0 I = 12.0 h = 0.0025 l=2.0 cycle = 10.0 t = np.arange(0, cycle, h) n = (int)((cycle)/h) initial_angle = 90.0 y=np.zeros(n) v=np.zeros(n) def accel(theta): return -(m*g*r/I)*np.sin(theta) y[0] = np.radians(initial_angle) v

How to eliminate negative solutions from `sympy.solve` result?

爱⌒轻易说出口 提交于 2019-12-11 07:44:11
问题 How can I make sympy.solve not return negative solutions? This seems to be a different task than adding a constraint like positive=True to the symbol I'm solving for. While import sympy x = sympy.symbols("x") print(sympy.solve(x**2-4, x)) x = sympy.symbols("x", positive=True) print(sympy.solve(x**2-4, x)) prints [-2, 2] [2] as expected - I still get a negative solve result for omega with import sympy omega, omega_0, gamma = sympy.symbols("omega, omega_0, gamma", real=True, positive=True) zeta

Scipy odeint Non-negative solution

心不动则不痛 提交于 2019-12-11 02:42:53
问题 Apparently, getting a non-negative solution from an ODE solver is non-trivial. In Matlab, there is the NonNegative option for certain solvers to get a non-negative solution. Is there a similar option in scipy? If not, what is the "best" way of imposing a non-negativity constraint? At the moment, I have something like the following: def f(x, t, params): ... ... ... ... ... ... x_dot[(x <= 0) * (x_dot <= 0)] = 0.0 return x_dot ... ... ... x = odeint(f, x0, t, args=params) However, this leads to

Update/Refresh matplotlib plots on second monitor

天大地大妈咪最大 提交于 2019-12-10 17:24:14
问题 At the moment I am working with Spyder and doing my plotting with matplotlib. I have two monitors, one for development and another for (data) browsing and other stuff. Since I am doing some calculations and my code often changes, I often (re)execute the code and have a look at the plots to check if the results are valid. Is there any way to place my matplotlib plots on a second monitor and refresh them from the main monitor? I have already searched for a solution but could not find anything.