scipy.signal not defined, but works after importing skimage

Advertisements I would like to use scipy.signal.convolve2d() function from SciPy, but signal is undefined: >>> import scipy … >>> conv = scipy.signal.convolve2d(data, kernel, mode="same") Error: Traceback (most recent call last): File "test.py", line n, in <module> conv = scipy.signal.convolve2d(data, kernel, mode="same") AttributeError: module ‘scipy’ has no attribute ‘signal’. But when I add skimage import: from… Read More scipy.signal not defined, but works after importing skimage

Scipy.integrate.odeint TypeError: Float object is not callable

Advertisements I am new to Python, and am trying to solve this differential equation using scipy.interpolate.odeint. However, I keep getting a TypeError. I have looked, and cannot find how to fix this issue to get the odeint module to work. Below is my code: import pandas as pd import matplotlib.pyplot as plt import numpy as… Read More Scipy.integrate.odeint TypeError: Float object is not callable

scipy.optimize.differential_evolution – unable to pass a function to optimize into it

Advertisements I would like to know where I made a mistake in the following code. I suspect it is some basic python mistake that has nothing to do with scipy. I am trying to pass a function to optimize to scipy.optimize.differential_evolution. def func_to_opt(x, TRANS_MIN_BV=TRANS_MIN_BV, SUBS_VAL=100, model=model): """Returns Rsp if BV is above TRANS_MIN_BV, SUBS_VAL if… Read More scipy.optimize.differential_evolution – unable to pass a function to optimize into it

eigenvectors created by numpy.linalg.eig have dots instead of data

Advertisements I want to calculate complex eigenvectors (Psi functions for shrodinger equation) for 20k*20k matrices, but always gets smth like this: [ 2.99009782e-09 -1.12381299e-08 -2.82346868e-08 …, 6.20967928e-34 -4.80675528e-34 -3.84848719e-35] [ 4.07337553e-08 -1.45976681e-07 -3.47961439e-07 …, 7.43558322e-34 -5.74815572e-34 -4.61317607e-35] [ 5.51921102e-07 -1.88491289e-06 -4.26000711e-06 …, 9.29535407e-34 -7.15304083e-34 -5.78846547e-35] As I understand it just replaces part of data with… Read More eigenvectors created by numpy.linalg.eig have dots instead of data

Understanding broadcasting and arithmetic operations on different dimension tensors

Advertisements I’m currently working on computing various similarity metrics between vectors such as cosine similarity, euclidean distance, mahalanobis distance, etc. As I’m working with vectors that can be very large, I need compute time to be minimal. I’m struggling to understand how to work with vectors of different dimensions (they, do, however, share one dimension)… Read More Understanding broadcasting and arithmetic operations on different dimension tensors

How to perform binomial-coefficient and factorial calculation with more precision?

Advertisements I was comparing the result of my following python calculation with Mathematica: https://www.wolframalpha.com/input?i=sum+%28500+choose+r+%29%28-1%29%5Er+%2F%28r%21%29+%2C+r%3D0+to+500 import numpy as np from decimal import * import scipy.special from scipy.special import factorial getcontext().prec = 30 i = 500 sum(np.array([scipy.special.comb(Decimal(i), (r), exact=True)*pow(-1, r)/Decimal(factorial(r, exact=False)) for r in range(i+1)])) Both calculations are giving almost same value until i = 400 but… Read More How to perform binomial-coefficient and factorial calculation with more precision?