I have a pandas DataFrame containing two columns [‘A’, ‘B’]. Each column is made up of integers. I want to construct a sparse matrix with the following properties: row index is all integers from 0 to the max value in the dataframe column index is the same as row index entry i,j = 1 if [i,j] or [j,i] is a
Tag: scipy
How to draw colored rectangles around grouped clusters in dendogram?
I try to add colored rectangle to dendrogram results like as follow: this is my dendrogram codes: However, this is only add colorful line not a rectangle like in the above image. How can I create image like this? Thanks Answer You can loop through the generated path collections and draw a bounding box. Optionally, you could set the height
Pulling x-values of spline integer y-values?
I have the given sample data and interpolated spline: I would like to pull the x values that correspond to the integer y values of the spline, but am not sure how to do this. I assume I will be using np.where() and have tried (to no avail): Answer You could use the find_roots function from this post to find
How to hide `delta_grad == 0.0` warning in scipy.optimize.minimize?
I have a loop that executes several hundred optimizations using scipy.optimize.minimize. Unfortunately, I keep getting this annoying warning: Because I am running hundreds of optimizations, this warning shows up dozens and dozens of times during the loop, and it just clutters the console and obscures the rest of my program’s output. Is there a way to either Check if this
Fitting data to a complementary error function with multiple variables in Python
I am having trouble to fit experimental data to a complementary error function in Python 3.7.4. More precisely, I want to fit my data to the complementary error function consisting of the integrand function with the parameters a, b, c, and the cerf function doing the actual integration. The integration should go from x (the argument of the function) to
stats.ttest_ind() vs. “manual” computation of Student’s independent t-test: different results
I am comparing stats.ttest_ind() vs “manual” computation of the same test, and get different results. stats.ttest_ind() method: Out: Manual method: Out: We can see there’s a small difference. Why? Maybe because of how stats.ttest_ind() computes degrees of freedom? Any insight much appreciated. Answer The following works. It is your code from above, with only two rows changed. and it outputs
Compute sum of power of large sparse matrix
Given a query vector (one-hot-vector) q with size of 50000×1 and a large sparse matrix A with size of 50000 x 50000 and nnz of A is 0.3 billion, I want to compute r=(A + A^2 + … + A^S)q (usually 4 <= S <=6). I can above equation iteratively using loop but I want to more fast method. First
Eucledian distance to point source
I am stimulating a model via a point source, which is located above (z-direction)– to be able to compute the impact of the stimulation i need to compute the eucledian distance from this point power source to each mid of compartment (see picute). I tried it this way, but the results are strange — maybe the computation of the distance
How to put initial condition of ODE at a specific time point using odeint in Python?
How to put initial condition of ODE at a specific time point using odeint in Python? So I have y(0) = 5 as initial condition, following code works:: I wanna see the graph in both negative and positive time line. So I change t = np.linspace(0,20) to t = np.linspace(-5,20), but then the initial condition is taken as y(-5) =
Weibull: R vs Python – slightly different results
I’m trying to replicate R’s fitdist() results (reference, cannot modify R code) in Python using scipy.stats. The results are quite close but still different (difference is at not acceptable level). Does anybody know why the results are different? How can I reduce the difference between the results? scipy_stats.weibull_min definition (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.weibull_min.html) seems to be the same as R’s weibull (https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Weibull.html. Data