PCA visualisation - np.outer() error.

55 views
Skip to first unread message

Thibault Tubiana

unread,
Jan 21, 2022, 10:56:25 AM1/21/22
to MDnalysis discussion
Dear all,

I tried to reproduce the PCA tutorial (https://userguide.mdanalysis.org/dev/examples/analysis/reduced_dimensions/pca.html) but the command "projected = np.outer(trans1, pc1) + pc.mean" gave me this error : ValueError: operands could not be broadcast together with shapes (98,2565) (855,3)
I have mdanalysis version 2.0, numpy version 1.22.1 and OS is MacOS 10.12.

Do someone knows how to fix it ?
Thank you :-)
Best regards,
Thibault Tubiana.

Oliver Beckstein

unread,
Jan 21, 2022, 12:15:23 PM1/21/22
to mdnalysis-discussion
Hi Thibault,

Welcome to the MDAnalysis mailing list.

You discovered a bug in the latest version of the user guide. It should read

projected = np.outer(trans1, pc1) + pc.mean.flatten()

because at this point, the outer product has shape (98,2565) so we reshape pc.mean into an 1d array with 2565 components. Then the rest works.

coordinates = projected.reshape(len(trans1), -1, 3)
proj1 = mda.Merge(backbone)
proj1.load_new(coordinates, order="fac”)
# write PDB and TRR for viz in external program
proj1.atoms.write("bb.pdb”)
proj1.atoms.write("bb.trr", frames="all”)


Hope this helps.

Oliver
> --
> You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mdnalysis-discussion/e7056092-5e9d-4306-b2e0-a314d468a8a4n%40googlegroups.com.

--
Oliver Beckstein (he/his/him)
orbe...@gmail.com







Thibault Tubiana

unread,
Jan 23, 2022, 4:15:08 PM1/23/22
to MDnalysis discussion
Thank you so much for your fast Help :-)

Best regards,
Thibault.

Reply all
Reply to author
Forward
0 new messages