Assuming you have a python3 environment, get numpy by typing pip3 install numpy
at the command line, or python3 -m pip install numpy
or perhaps py -m pip install numpy
if under Windows. Here is some code:
% Doesn't try to convert complex Python objects to Prolog.
raw(Cmd,Out) :- py_call(Cmd,Out,[py_object(true)]).
% Tries to convert Python objects to Prolog.
cmd(Cmd,Out) :- py_call(Cmd,Out).
% Multiply two vectors.
example1 :-
X = [1,2,3,4],
Y = [2,3,4,5],
raw(numpy:array(X),V1),
raw(numpy:array(Y),V2),
raw(numpy:multiply(V1,V2),V3),
cmd(numpy:ndarray:tolist(V3), Out),
writeln(Out).
% Square a matrix.
example2 :-
X = [[1,2,3],
[3,5,3],
[0,2,1]],
raw(numpy:array(X),M),
raw(numpy:matmul(X,X),Square),
cmd(numpy:ndarray:tolist(Square),Out),
writeln(Out).
It works as advertised by I’d note that getting something wrong (e.g. a typo) in py_call results in the REPL going into an infinite loop, but I’m sure that will be ironed out in due course.
There is an API reference for the vast array of function calls available to you here:
https://numpy.org/doc/stable/reference/index.html
If you want to put together a specific example I may be able to help!
NB: The NumPy linear algebra functions rely on BLAS and LAPACK to provide efficient low level implementations of standard linear algebra algorithms. Those libraries may be provided by NumPy itself using C versions of a subset of their reference implementations but, when possible, highly optimized libraries that take advantage of specialized processor functionality are preferred. Examples of such libraries are OpenBLAS, MKL ™, and ATLAS. Because those libraries are multithreaded and processor dependent, environmental variables and external packages such as threadpoolctl may be needed to control the number of threads or specify the processor architecture.