scipy

Maintaining Sharp Corners in a Numpy Interpolation

Maintaining Sharp Corners in a Numpy Interpolation Question: I am interpolating a shape with numpy’s linspace and interp using gboffi‘s magnificent code from this post (included, below). This works well, however, the corners sometimes get missed and the resulting softened shape is undesired. I’d like to maintain the sharp corners of my shapes with an …

Total answers: 4

Get Evenly Spaced Points from a Curved Shape

Get Evenly Spaced Points from a Curved Shape Question: How may I take a shape that was created with more points at its curves and subdivide it so that the points are distributed more equally along the curve? In my research I thought that numpy‘s interp might be the right function to use, but I …

Total answers: 3

max function within integrate.quadrature fails

max function within integrate.quadrature fails Question: The following basic Python script fails: from scipy import integrate integrate.quadrature(lambda t: max(1,t), -2, 2)[0] with the error message: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() It looks to me that the integrate.quadrature command does not like the …

Total answers: 1

How can I add Rayleigh noise to an image in python?

How can I add Rayleigh noise to an image in python? Question: I am doing the following image processing using cv2: import numpy as np import cv2 image = cv2.imread(‘./tomatoes.png’,cv2.IMREAD_GRAYSCALE) noise_std = 0.1 noise = np.random.rayleigh(noise_std, image.shape) noisy_image = image + noise cv2.imwrite(‘noisy_image.jpg’, noisy_image) cv2.imshow(‘Noisy Image’, noisy_image) cv2.waitKey(0) The problem is: I only receive a …

Total answers: 1

How do I calculate the matrix exponential of a sparse matrix?

How do I calculate the matrix exponential of a sparse matrix? Question: I’m trying to find the matrix exponential of a sparse matrix: import numpy as np b = np.array([[1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, …

Total answers: 1

Pandas spline interpolation wrong?

Pandas spline interpolation wrong? Question: Pandas (Version 1.3.5) and SciPy (Version 1.7.3) give different result for spline interpolation and from my understanding pandas is wrong: df = pd.DataFrame(data = {‘values’: [10, 12, 15, None, None, None, None, 10, 5, 1, None, 0, 1, 3],}) df[‘interpolated_pandas’] = df[‘values’].interpolate(method=’spline’, axis=0, order=3) df[[‘interpolated_pandas’, ‘values’]].plot.line(); gives me: And idx …

Total answers: 2

How to get linear value from Dataframe

How to get linear value from Dataframe Question: I have simple question. i want to get linear value with dataframe.(like N-D Lookuptable in Matlab simulink) type python import numpy as np import scipy as sp import pandas as pd X = np.array([100,200,300,400,500]) Y = np.array([1,2,3]) W = np.array([[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3]]) df = pd.DataFrame(W,index=Y,columns=X) # 100 200 300 …

Total answers: 1

Curve fitting with three unknowns Python

Curve fitting with three unknowns Python Question: I have a data set where from one x I can obtain the exponential function f(x) = a*np.exp(-b*(x-c)) , defined in Python like this: def func(x, a, b, c): return a*np.exp(-b*(x-c)) f = func(x, a, b, c) a = 1.6 b = 0.02 a, b, c are all …

Total answers: 1

Finding basis of affine space in python?

Finding basis of affine space in python? Question: Suppose I am given an affine space as some conjunction of equalities say: x + y + z = 2 && x – 3z = 4 which I represent in python as: [ [1,1,1,2] , [1,0,-3,4] ] I would like to find the basis of this affine …

Total answers: 1

Scipy 3D Delaunay. Different results when translating the set of points

Scipy 3D Delaunay. Different results when translating the set of points Question: I thought that given a set of points, the 3D Delaunay network would be unique. But moving all the points (without changing the relative distances) gives a different result. import numpy as np from scipy.spatial import Delaunay points = np.array([ [-0.6, -0.1, -1.5], …

Total answers: 1