scientific-computing

scipys quadrature function complains about perfectly sane lambda?

scipys quadrature function complains about perfectly sane lambda? Question: I have 2 versions of a snippet one works one doesn’t, this works: f = lambda x : x * 2.0 * pi print(scipy.integrate.quadrature(f, 0.0, 1.0)) This fails: f = lambda x : math.exp(x * 2.0 * pi)` print(scipy.integrate.quadrature(f, 0.0, 1.0)) With error: TypeError: only size-1 …

Total answers: 1

How do I plot data from multiple CSVs each with different column numbers

How do I plot data from multiple CSVs each with different column numbers Question: The file has no header but I would need to select say columns, 5,9, 13, 17 etc against column 2 (time). How can this be achieved in the case where the headers are present as well. Edit : Each file contains …

Total answers: 2

Numercially stable softmax

Numerically stable softmax Question: Is there a numerically stable way to compute softmax function below? I am getting values that becomes Nans in Neural network code. np.exp(x)/np.sum(np.exp(y)) Asked By: Abhishek Bhatia || Source Answers: There is nothing wrong with calculating the softmax function as it is in your case. The problem seems to come from …

Total answers: 4

How to find Bragg reflexes fast with numpy?

How to find Bragg reflexes fast with numpy? Question: For x-ray diffraction one needs to find the solutions to the so called Laue-Equation G_hkl – k_in + |k_in|*(sin(theta) cos(phi) , sin(theta) sin(phi) , cos(theta))=0 where G_hkl is a given 3 dimensional vector, k_in can be chosen as (0,0,1) and theta and phi are free parameters …

Total answers: 2

Update/Refresh matplotlib plots on second monitor

Update/Refresh matplotlib plots on second monitor Question: 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 …

Total answers: 2

Processing large amount of data in Python

Processing large amount of data in Python Question: I have been trying to process a good chunk of data (a few GBs) but my personal computer resists to do it in a reasonable time span, so I was wondering what options do I have? I was using python’s csv.reader but it was painfully slow even …

Total answers: 2

binning data in python with scipy/numpy

binning data in python with scipy/numpy Question: is there a more efficient way to take an average of an array in prespecified bins? for example, i have an array of numbers and an array corresponding to bin start and end positions in that array, and I want to just take the mean in those bins? …

Total answers: 6

True or false output based on a probability

True or false output based on a probability Question: Is there a standard function for Python which outputs True or False probabilistically based on the input of a random number from 0 to 1? example of what I mean: def decision(probability): …code goes here… return …True or False… the above example if given an input …

Total answers: 5

Interactive large plot with ~20 million sample points and gigabytes of data

Interactive large plot with ~20 million sample points and gigabytes of data Question: I have got a problem (with my RAM) here: it’s not able to hold the data I want to plot. I do have sufficient HD space. Is there any solution to avoid that “shadowing” of my data-set? Concretely I deal with Digital …

Total answers: 6