Is there a numpy function for generating sequences similar to R’s seq function?

Yes! An easy way to do this will be using numpy.linspace Numpy Docs numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) Return evenly spaced numbers over a specified interval. Returns num evenly spaced samples, calculated over the interval [start, stop]. The endpoint of the interval can optionally be excluded. Example: [In 1] np.linspace(start=0, stop=50, num=5) [Out 1] … Read more

NumPy “record array” or “structured array” or “recarray”

The answer in a nutshell is you should generally use structured arrays rather than recarrays because structured arrays are faster and the only advantage of recarrays is to allow you to write arr.x instead of arr[‘x’], which can be a convenient shortcut, but also error prone if your column names conflict with numpy methods/attributes. See … Read more

Improving FFT performance in Python

You could certainly wrap whatever FFT implementation that you wanted to test using Cython or other like-minded tools that allow you to access external libraries. GPU-based If you’re going to test FFT implementations, you might also take a look at GPU-based codes (if you have access to the proper hardware). There are several: reikna.fft, scikits.cuda. … Read more

What is the difference between resize and reshape when using arrays in NumPy?

Reshape doesn’t change the data as mentioned here. Resize changes the data as can be seen here. Here are some examples: >>> numpy.random.rand(2,3) array([[ 0.6832785 , 0.23452056, 0.25131171], [ 0.81549186, 0.64789272, 0.48778127]]) >>> ar = numpy.random.rand(2,3) >>> ar.reshape(1,6) array([[ 0.43968751, 0.95057451, 0.54744355, 0.33887095, 0.95809916, 0.88722904]]) >>> ar array([[ 0.43968751, 0.95057451, 0.54744355], [ 0.33887095, 0.95809916, 0.88722904]]) … Read more

ValueError: Can’t convert non-rectangular Python sequence to Tensor

I’m not sure whether they exist in TensorFlow 1 but TensorFlow 2.0 supports RaggedTensors, which the documentation describes as “… the TensorFlow equivalent of nested variable-length lists.” I think it would be trivial to convert your data to RaggedTensors. It might even be as easy as: data_tensor = tf.ragged.constant(data) Example: >>> a = tf.ragged.constant([[1],[2,3]]) >>> … Read more

sigmoidal regression with scipy, numpy, python, etc

Using scipy.optimize.leastsq: import numpy as np import matplotlib.pyplot as plt import scipy.optimize def sigmoid(p,x): x0,y0,c,k=p y = c / (1 + np.exp(-k*(x-x0))) + y0 return y def residuals(p,x,y): return y – sigmoid(p,x) def resize(arr,lower=0.0,upper=1.0): arr=arr.copy() if lower>upper: lower,upper=upper,lower arr -= arr.min() arr *= (upper-lower)/arr.max() arr += lower return arr # raw data x = np.array([821,576,473,377,326],dtype=”float”) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)