Skip to main content

Implementation of the Observer pattern for NumPy arrays.

Project description

PyPIl PyPIv Anaconda-Server Badge

Implementation of the Observer pattern for NumPy arrays.

Example

from numpy import array
from ndarray_listener import ndarray_listener as ndl

a = ndl(array([-0.5, 0.1, 1.1]))

class Observer(object):
  def __init__(self):
    self.called_me = False

  def __call__(self, _):
    self.called_me = True

o = Observer()
a.talk_to(o)
print(o.called_me)
a[0] = 1.2
print(o.called_me)

The output should be

False
True

Installing

The recommended way of installing it is via conda

conda install -c conda-forge ndarray-listener

An alternative way would be via pip

pip install ndarray-listener

Running the tests

After installation, you can test it

python -c "import ndarray_listener; ndarray_listener.test()"

as long as you have pytest.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndarray-listener-1.0.20.tar.gz (4.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page