Python print every unique combination of list items

What is the cleanest (most "pythonic") way of printing every unique combination of three items in the following list? strats = ["1","2","3","4"] The solution needs to avoid duplicates: 1 and 1 and 1 No (not unique) 1 and 1 and 2 No (not unique) 1 and 1 and 3 No (not unique) … 1 and… Read More Python print every unique combination of list items

scipy.optimize.differential_evolution – unable to pass a function to optimize into it

I would like to know where I made a mistake in the following code. I suspect it is some basic python mistake that has nothing to do with scipy. I am trying to pass a function to optimize to scipy.optimize.differential_evolution. def func_to_opt(x, TRANS_MIN_BV=TRANS_MIN_BV, SUBS_VAL=100, model=model): """Returns Rsp if BV is above TRANS_MIN_BV, SUBS_VAL if not.… Read More scipy.optimize.differential_evolution – unable to pass a function to optimize into it

eigenvectors created by numpy.linalg.eig have dots instead of data

I want to calculate complex eigenvectors (Psi functions for shrodinger equation) for 20k*20k matrices, but always gets smth like this: [ 2.99009782e-09 -1.12381299e-08 -2.82346868e-08 …, 6.20967928e-34 -4.80675528e-34 -3.84848719e-35] [ 4.07337553e-08 -1.45976681e-07 -3.47961439e-07 …, 7.43558322e-34 -5.74815572e-34 -4.61317607e-35] [ 5.51921102e-07 -1.88491289e-06 -4.26000711e-06 …, 9.29535407e-34 -7.15304083e-34 -5.78846547e-35] As I understand it just replaces part of data with dots,… Read More eigenvectors created by numpy.linalg.eig have dots instead of data

Understanding broadcasting and arithmetic operations on different dimension tensors

I’m currently working on computing various similarity metrics between vectors such as cosine similarity, euclidean distance, mahalanobis distance, etc. As I’m working with vectors that can be very large, I need compute time to be minimal. I’m struggling to understand how to work with vectors of different dimensions (they, do, however, share one dimension) and… Read More Understanding broadcasting and arithmetic operations on different dimension tensors

How to perform binomial-coefficient and factorial calculation with more precision?

I was comparing the result of my following python calculation with Mathematica: https://www.wolframalpha.com/input?i=sum+%28500+choose+r+%29%28-1%29%5Er+%2F%28r%21%29+%2C+r%3D0+to+500 import numpy as np from decimal import * import scipy.special from scipy.special import factorial getcontext().prec = 30 i = 500 sum(np.array([scipy.special.comb(Decimal(i), (r), exact=True)*pow(-1, r)/Decimal(factorial(r, exact=False)) for r in range(i+1)])) Both calculations are giving almost same value until i = 400 but failing… Read More How to perform binomial-coefficient and factorial calculation with more precision?