DelphiPythonPython GUIWindows

Learn To Build A Python GUI For Scientific Computing With The NumPy Library In A Delphi Windows App

blogbanner3 28

If you need to perform complex transformations or mathematical calculations with matrices or arrays, then Python’s Numpy library is exactly what you need. You can easily run this library and give it a nice GUI using Python4Delphi (P4D). Python4Delphi is a free tool that allows you to work with Python scripts and objects, even create new Python modules and types in the Windows GUI.

The NumPy library is a popular Python library used for scientific computing applications, and is an acronym for “Numerical Python”. NumPy is the fundamental package for array computing with Python.

NumPy’s operations are divided into three main categories: Fourier Transform and Shape Manipulation, Mathematical and Logical Operations, and Linear Algebra and Random Number Generation. To make it as fast as possible, NumPy is written in C and Python.

Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.

This post will guide you on how to run the NumPy library using Python for Delphi to display it in the Delphi Windows GUI app.

First, open and run our Python GUI using project Demo01 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute script button, and get the result in the upper Memo. You can find the Demo01 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.

0 rundemo1 6813476

 

1. Create a Matrix and Get Some Properties

This example shows how to create a 3-dimensional array and fill it with numbers from 0 to 29. Then, using the properties of this array, we can find out its shape, dimension, data type, number of elements:

Let’s see the output in our P4D VCL:

1 1 9822691

 

2. Basic Operations with Arrays

Let’s take a look at the simplest conversions you can perform on arrays. Using concatenate() function, you can combine the values of two arrays into one. With function sort() you can sort ascending the values in an array. Function reshape() allows you to change the dimension of the array:

The result:

1 2 5010245

 

3. Create an Array of All Zeros

We can use the zeros method to create an array of all zeros as shown below:

The result in Python GUI:

1 3 3425676

Congratulations, now you have learned how to run the NumPy library using Python for Delphi to display it in the Delphi Windows GUI app! These are only some basic examples of what Numpy library allows us to do. 


Check out the numpy for numerical computing library for Python and use it in your projects: https://pypi.org/project/numpy/ and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi


References & further readings

[1] Hakim, M. A. (2024).

Article03 – NumPy. pythongui.orgRepo_Python4Delphi-Python-Libraries GitHub. github.com/MuhammadAzizulHakim/ pythongui.orgRepo_Python4Delphi-Python-Libraries/tree/main/Article03%20-%20NumPy

[2] Malik, U. (2018).

NumPy Tutorial: A Simple Example-Based Guide. StackAbuse. stackabuse.com/numpy-tutorial-a-simple-example-based-guide

[3] NumPy (2023).

NumPy: The fundamental package for scientific computing with Python. NumPy Website. numpy.org

[4] PyPI (Python Package Index). (2023).

numpy 1.24.2: Fundamental package for array computing in Python. Python Software Foundation. pypi.org/project/numpy

Related posts
CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And NumPy Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Generative Adversarial Networks (GANs) - The Engine behind DALL-E

CodeIDELearn PythonPythonPython GUITkinter

How To Make 20 ChatGPT Prompts Work With Python GUI Builders And Matplotlib Library?

CodeIDELearn PythonPythonPython GUITkinter

How To Make 20 ChatGPT Prompts Work With Python GUI Builders And Pillow Library?

Leave a Reply

Your email address will not be published. Required fields are marked *