Posts

Showing posts with the label linear-algebra

scipy multivariate_normal(allow_singular=True) in GMM

Image
Clash Royale CLAN TAG #URR8PPP scipy multivariate_normal(allow_singular=True) in GMM During the calculation of a Gaussian Mixture Model I have to calculate the pdf() of the multivariate Gaussian distribution. I do this using the scipy multivariate_normal() method. Now during the calculations I encounter the situation that I get an error which says LinAlgError: singular matrix Setting the allow_singular parameter of the scipy multivariate_normal() = True circumvents this error and I get a quite meaningful result: So how is scipy "allowing" for singularity and what are the consequences for the calculations? --> If there are no consequences, strictly speaking, this parameter could be set to TRUE by default (but it isn't). By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is...

np.dot 3x3 with N 1x3 arrays

Image
Clash Royale CLAN TAG #URR8PPP np.dot 3x3 with N 1x3 arrays I have an ndarray of N 1x3 arrays I'd like to perform dot multiplication with a 3x3 matrix. I can't seem to figure out an efficient way to do this, as all the multi_dot and tensordot, etc methods seem to recursively sum or multiply the results of each operation. I simply want to apply a dot multiply the same way you can apply a scalar. I can do this with a for loop or list comprehension but it is much too slow for my application. N = np.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9], ...]) m = np.asarray([[10, 20, 30], [40, 50, 60], [70, 80, 90]]) I'd like to perform something such as this but without any python loops: np.asarray([np.dot(m, a) for a in N]) so that it simply returns [m * N[0], m * N[1], m * N[2], ...] [m * N[0], m * N[1], m * N[2], ...] What's the most efficient way to do this? And is there a way to do this so that if N is just a single 1x3 matrix, it will just output the same as np.dot(m, N)? ...