.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/numpy_integration.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_numpy_integration.py: NumPy integration ================= It is possible to easily go between numpy and apytypes and therefore also use plotting tools like Matplotlib in an integrated manner. Consider the example from https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve.html implemented using fixed-point arithmetic .. GENERATED FROM PYTHON SOURCE LINES 10-25 .. code-block:: Python import numpy as np from scipy import signal from apytypes import APyFixedArray, convolve import matplotlib.pyplot as plt sig = np.repeat([0.0, 1.0, 0.0], 100) sig_fx = APyFixedArray.from_float(sig, 12, 2) win = signal.windows.hann(50) win_fx = APyFixedArray.from_float(win, 10, 2) filtered = signal.convolve(sig, win, mode="same") / sum(win) filtered_fx = convolve(sig_fx, win_fx, mode="same") / sum(win_fx) .. GENERATED FROM PYTHON SOURCE LINES 26-27 The results can then be plotted in Matplotlib .. GENERATED FROM PYTHON SOURCE LINES 27-43 .. code-block:: Python fig, (ax_orig, ax_win, ax_filt) = plt.subplots(3, 1, sharex=True) ax_orig.plot(sig) ax_orig.plot(sig_fx) ax_orig.set_title("Original pulse") ax_orig.margins(0, 0.1) ax_win.plot(win) ax_win.plot(win_fx) ax_win.set_title("Filter impulse response") ax_win.margins(0, 0.1) ax_filt.plot(filtered) ax_filt.plot(filtered_fx) ax_filt.set_title("Filtered signal") ax_filt.margins(0, 0.1) fig.tight_layout() fig.show() .. image-sg:: /examples/images/sphx_glr_numpy_integration_001.png :alt: Original pulse, Filter impulse response, Filtered signal :srcset: /examples/images/sphx_glr_numpy_integration_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.549 seconds) .. _sphx_glr_download_examples_numpy_integration.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: numpy_integration.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: numpy_integration.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: numpy_integration.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_