python - I have a gaussian function with two independent discrete variables. How do I create a matrix of all possible values? -
basically have this:
from scip.stats import norm import pandas pd r = pd.series([1, 2, 3]) k = pd.series([0.2, 0.3, 0.4, 0.5]) x = 2 mean = x + k variance = k # i'm feeding gaussian function 2 vectors. # i'd matrix of possible combinations. quickly. values = norm.pdf(r, mean, variance) so i'm giving function norm.pdf 2 vectors of data, , i'd (3x4) matrix returned me looks like:
values(1, 0.2) values(1, 0.3) values(1, 0.4) values(1, 0.5) values(2, 0.2) ... values(3, 0.2) ... values(4, 0.2) ........... ........... values(4, 0.5) i know iterate on items in arrays, takes lot of time, , plan on scaling quite bit. i'd take advantage of numpy's speed. i've tried vectorizing, fails. ideas? thanks!!!
you can apply pdf each element of r , automatically put results in matrix using:
r.apply(lambda x: pd.series(norm.pdf(x, mean, variance), index=k)) if return series apply results automatically unpacked columns. output:
0.2 0.3 0.4 0.5 0 3.037941e-08 0.000111 0.002182 0.008864 1 1.209854e+00 0.806569 0.604927 0.483941 2 6.691511e-04 0.087406 0.323794 0.483941
Comments
Post a Comment