-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, I have a stack of vectors: v1 = np.arange(3) v2 = np.arange(3) + 3 stack = np.vstack(v1, v2) (now stack is : array([[0, 1, 2], [3, 4, 5]])) and a 3d matrix: mat = np.dstack((np.eye(3), np.eye(3) * 2)) (mat is now array([[[ 1., 2.], [ 0., 0.], [ 0., 0.]], [[ 0., 0.], [ 1., 2.], [ 0., 0.]], [[ 0., 0.], [ 0., 0.], [ 1., 2.]]])) I'm looking for the operation needed to get the two (stacked) vectors array([[0, 1, 2], [6, 8, 10]])) or its transpose. I tried various combinations of tensor products, but I always get a result in 3 dimensions, while I just want two. Any suggestions ? Thanks, Martin -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJOk9jWAAoJEBdvyODiyJI4y30IAJu6YIHK+ED8pN5M2TFrEKj8 k/K22MjitlQ8wTFDxwc5xBRI+yoniqgAfpzWjdU3pc5MxzXRgbZrRZagYWjepZyI CtN/CHy+BfM8EPJulFeVcInAgo1pgfAhH4xwEakbu88XhKSgat1Y9xlNRcrohTUQ oBVd+DNmBYpEUAa0pDjkMYXM8vaJqzePZZGaviZxY0AY2MBDrbZN/z6t4u2Unajn 8X1vjCg/XfDbm9v7FK/52MUorAJinZRdHiWBTE9rOmAqjJxTBoFKkN+0FMTUk6Sj acJNjr5KFjl6o3JPxqU4jRfw1zFRO9BEouzosKfYcs/kLozNjTBmfZztg0np/dg= =Ykij -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 11/10/11 07:49, Martin Raspaud wrote:
Hi all, [...] I'm looking for the operation needed to get the two (stacked) vectors array([[0, 1, 2], [6, 8, 10]])) or its transpose.
Hi again, Here is a solution I just found: np.einsum("ik, jki->ij", stack, mat) array([[ 0., 1., 2.], [ 6., 8., 10.]]) Best regards, Martin -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJOlBEDAAoJEBdvyODiyJI4DTQH/ikl8Rb1Lx5qakyS4IoXcBos lPyKk7s+AEA6dthxDJP+O5v+YQsMxR1f5Swx1rJ2OJxjmJ/6Rb8yphMMdX89kgkL VhMIpDwre8/KyReTl1CT2chWtOtz8B46Pn1ivhDbNfvCUBc39v2ymJXV2bZCYzBD fn1phhoYgmo3zsnnj3w6CSjAjsJmaI4+OuLAsd2IXWUmN8/CmwwAIBL9tlzrhmBR n5N1gEq9YV7LYgxjeoG47NkbLe0GbLTVWUb7H5/3GvoXh6bKtrujtPeWaMTVLeIo q/n8Cg8977WSpR1W1soBEMf/nCdLs7IeqlN7utjOTI33UOo07hssb+xtfwv2By8= =UU5t -----END PGP SIGNATURE-----
I don't really understand the operation you have in mind that should lead to your desired result, so here's a way to get it that discards most of mat's content: (which does not seem needed to compute what you want): (stack.T * mat[0, 0]).T -=- Olivier 2011/10/11 Martin Raspaud <martin.raspaud@smhi.se>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi all,
I have a stack of vectors:
v1 = np.arange(3) v2 = np.arange(3) + 3 stack = np.vstack(v1, v2)
(now stack is : array([[0, 1, 2], [3, 4, 5]]))
and a 3d matrix:
mat = np.dstack((np.eye(3), np.eye(3) * 2)) (mat is now array([[[ 1., 2.], [ 0., 0.], [ 0., 0.]],
[[ 0., 0.], [ 1., 2.], [ 0., 0.]],
[[ 0., 0.], [ 0., 0.], [ 1., 2.]]]))
I'm looking for the operation needed to get the two (stacked) vectors array([[0, 1, 2], [6, 8, 10]])) or its transpose.
I tried various combinations of tensor products, but I always get a result in 3 dimensions, while I just want two.
Any suggestions ?
Thanks, Martin -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJOk9jWAAoJEBdvyODiyJI4y30IAJu6YIHK+ED8pN5M2TFrEKj8 k/K22MjitlQ8wTFDxwc5xBRI+yoniqgAfpzWjdU3pc5MxzXRgbZrRZagYWjepZyI CtN/CHy+BfM8EPJulFeVcInAgo1pgfAhH4xwEakbu88XhKSgat1Y9xlNRcrohTUQ oBVd+DNmBYpEUAa0pDjkMYXM8vaJqzePZZGaviZxY0AY2MBDrbZN/z6t4u2Unajn 8X1vjCg/XfDbm9v7FK/52MUorAJinZRdHiWBTE9rOmAqjJxTBoFKkN+0FMTUk6Sj acJNjr5KFjl6o3JPxqU4jRfw1zFRO9BEouzosKfYcs/kLozNjTBmfZztg0np/dg= =Ykij -----END PGP SIGNATURE-----
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Martin Raspaud
-
Olivier Delalleau