Using numpy for my algo?

Hello, I have an algo that uses numpy, but it is not installed on the server running that algo, so it just crashes, anyone knows a workaround?

Copy the numpy files into your algo, and import from there rather than the default python location. However, there may be problems uploading your zip file, I don’t know if it has been changed to allow larger file sizes.

I’m not sure if this would work since Numpy makes use of bindings to linear algebra libraries. Can anyone confirm that they successfully made use of Numpy in their algorithm?

Yes I did, but as I also said (see quote above your comment) I cannot upload the code anymore.

Also: I have literally zero knowlage about python, I only know c++
I read, that numpy uses compiled libraries, so I think, that even if this works on my PC (I installed numpy and than copied the files into the alg folder), it might not work on a linux server… But I might be wrong, and the only issue at the moment is the filesize.

My folder struckture:
algos
|-documentation
|-gamelib
|-numpy
| algo_strategy.py

In algo_strategy.py:

import gamelib
import random
import math
import warnings
import sys
sys.path.append(’/’)
import numpy as np
from sys import maxsize


def on_turn(self, turn_state):
a = np.matrix(‘1 2; 3 4’)
b = np.matrix(‘1 2; 3 4’)
c=a*b
gamelib.debug_write('a: {} b: {} c: {} '.format(c[0,0] , c[1,0] , c[0,1]))

I blindly guess that if matrix multiplication works, the rest does too.

Unless you really need matrix operations, Python lists have a lot of useful functions. Check this https://docs.python.org/3/tutorial/datastructures.html

You can also create few user-defined functions to do any matrix operations using lists, and avoid numpy. I don’t think you need them to be super optimized as the arena grid is just 28x28

Hi Jakobimatrix,

I tried to to do as you did but when I launch the powershell to run a match, I get :

ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try git clean -xdf (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name 'multiarray' from 'numpy.core'

Even so numpy works fine when used normally. I tried to reinstall it but the problem remains.

Did you just copy the numpy folder without doing anything else? (I copy mine from Anaconda\envs\my_env\Lib\site-packages)

I anyone has an idea, I’ll gladly accept it :slight_smile:
Thanks!

Edit: After few hours and as much teeth broken, I found a way to make it work : in the run.ps1 file of my algo, I changed this line py -3 $algoPath to this python $algoPath

Glad you could fix your problem by yourself.

For your question: yes i just copied the numpy folder inside the algo folder and
import sys
sys.path.append(’/’)
import numpy as np
would now use the copied folder instaed of the installed version

Thanks for the answer! I don’t know why this does not work for me…

For the information, the change I made allows me to use installed librairies

lol so now I’m a part of the “please add numpy” club. Currently made my folder structure and my import information to the same as Jakobimatrix has suggested but I ran into arnby’s error. changed my run.ps1 like arnby suggested but it didn’t go away :confused: did you ever get yours working?

1 Like