Change sign of elements with an odd sum of indices

np.negative is silghtly faster than multiplying (as it is a ufunc) N = 5 arr = np.arange(N ** 3).reshape(N, N, N) %timeit arr.ravel()[1::2] *= -1 %timeit np.negative(arr.ravel()[1::2], out = arr.ravel()[1::2]) The slowest run took 8.74 times longer than the fastest. This could mean that an intermediate result is being cached. 100000 loops, best of 3: … Read more

Need a python module for numerical and scientific computing other than NumPy and SciPy

There is nothing unreliable about numpy’s behavior in the examples you show as compared to MATLAB, nor do any of the examples you show have anything to do with floating-point issues (with one exception). For the rounding behavior, MATLAB is the one doing it wrong here. Numpy is following the IEEE standard for rounding. The … Read more

how to do multiple scatter plots with matploatlib

You are a Udacity Machine Learning student? Something like this might be useful for you: import numpy as np import matplotlib.pyplot as plt labels = [‘output’,’varA’,’varB’,’varC’] data = np.array([[4,5,6,2,5], [3,6,4,6,3], [12,3,5,3,2], [4,1,1,44, 7]]) colors = [“r”, “g”, “b”, “k”] # make sure you have enough colors to match # the number of variables for i … Read more