GithubHelp home page GithubHelp logo

Comments (3)

peastman avatar peastman commented on May 26, 2024 1

A lot of numpy operation are implemented by calling methods on objects. As long as an object implements those methods, many things will "just work". You could actually make your code work by attaching units to a numpy array instead of to each element individually.

>>> unit_list1 = np.array([10, 20])*unit.femtoseconds
>>> np.std(unit_list1)
Quantity(value=5.0, unit=femtosecond)
>>> unit_list1 = np.array([10])*unit.femtoseconds
>>> np.std(unit_list1)
Quantity(value=0.0, unit=femtosecond)

from openmm.

peastman avatar peastman commented on May 26, 2024

Numpy isn't compatible with OpenMM units. It would be nice if you could pass quantities with units into arbitrary functions and have them always work, but that's often not the case. If you want to call Numpy functions, you should first convert the quantities to ordinary numbers in a chosen set of units.

from openmm.

SchroedingersLion avatar SchroedingersLion commented on May 26, 2024

Thanks Peter, so mixing the two isn't best practice then.
To be frank I was surprised that one could even use numpy functions on OpenMM objects. How does numpy know what to do with the units anyway?

from openmm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.