- Create a Windows GUI around you existing Python app.
- Add Python scripting to your Delphi Windows apps.
- Add parallel processing to your Python apps through Delphi threads.
- Enhance your speed sensitive Python apps with functions from Delphi for more speed.
|
1 2 3 4 |
procedure TForm1.Button1Click(Sender: TObject); begin PythonEngine1.ExecStrings( Memo1.Lines ); end; |
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.|
1 2 3 4 5 6 7 8 |
import numpy as np a = np.arange(30).reshape(2, 3, 5) print(a) print(a.shape) print(a.ndim) print(a.dtype.name) print(a.itemsize) print(a.size) |
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.|
1 2 3 4 5 6 7 8 |
import numpy as np arr = np.array([7, 10, 3, 11, 29, 15, 18]) print(np.sort(arr)) a = np.array([1, 2, 3, 4, 5, 6]) b = np.array([7, 8, 9, 10, 11, 12]) print(np.concatenate((a, b))) c = a.reshape(3, 2) print(c) |
Mathematical operations with matrix
Function default_rng() allows you to fill a matrix with random values. You can use integer or real numbers. In this example, we fill the matrix with integer values. Then we find the maximum and minimum element, the sum of all the elements in the matrix. It is also shown how you can multiply a matrix by a number and sum two matrices with the same dimension.|
1 2 3 4 5 6 7 8 9 10 11 12 |
import numpy as np from numpy.random import default_rng rng = default_rng() arr=rng.integers(20, size=(2, 4)) print(arr) print(arr.max()) print(arr.min()) print(arr.sum()) print(arr*2) arr2=rng.integers(5, size=(2, 4)) print(arr2) print(arr+arr2) |
And this is only a small part of what Numpy library allows you to do. Download Numpy and check how many possibilities it opens for your applications. Install Python4Delphi for building Python GUIs for Windows using Delphi easily.Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Free Delphi Community Edition Free C++Builder Community Edition










Can you bring values computed by numpy back to Delphi? And in reverse can you send values from Delphi to numpy?
I have a similar question to that of mr. Sauro. I use SciKit Learn to perform KMeans clustering. In the Python environment everything works as intended. The resulting classification is returned by Sklearn as ‘kmeans.labels_’ (numpy data type ‘ndarray’). I now want to import this numpy array back into Delphi. What would be the best way to do this?