12

Is there a good (small and light) alternative to numpy for python, to do linear algebra? I only need matrices (multiplication, addition), inverses, transposes and such.

Why?

I am tired of trying to install numpy/scipy - it is such a pita to get it to work - it never seems to install correctly (esp. since I have two machines, one linux and one windows): no matter what I do: compile it or install from pre-built binaries. How hard is it to make a "normal" installer that just works?

Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
  • 1
    Perhaps someone can help you with installation problems. Did you try the superpacks ([here](http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/) and [here](http://sourceforge.net/projects/scipy/files/scipy/0.10.0/))? If so, what went wrong? – Marcelo Cantos Nov 27 '11 at 21:34
  • I did try that - nothing went wrong. It installed fine - but i can't "import numpy" from python - as it doesn't find it! – Andriy Drozdyuk Nov 27 '11 at 21:36
  • Do you need to perform heavy calculation, or just a bunch of example matrices? I had just written some matrix-operation code the other day in pure Python. It is useless performance wise, but does the job otherwise, and I could make it public somewhere. – jsbueno Nov 27 '11 at 21:47
  • ok - just uploaded my code anyway - check answer bellow – jsbueno Nov 27 '11 at 22:15
  • Installing pre-built binaries of Numpy and Scipy is simple. Be ensured that you cannot find any other library replacement for them. – Developer Dec 15 '12 at 03:49
  • 1
    I am also looking for a lighter version, as using numpy creates a huge distribution when converting with py2exe, so this is a very valid thing to want. – Siwel Aug 26 '15 at 01:23
  • related: https://stackoverflow.com/q/45722188 – djvg Apr 06 '21 at 13:56

7 Answers7

3

I'm surprised nobody mentioned SymPy, which is written entirely in Python and does not require compilation like Numpy.

There is also tinynumpy, which is a pure python alternative to Numpy with limited features.

eadmaster
  • 1,347
  • 13
  • 23
  • Discussion of SymPy performance: https://docs.sympy.org/latest/modules/numeric-computation.html – djvg Apr 24 '20 at 05:48
2

I hear you, I have been there as well. Numpy/scipy are really wonderful libraries and it is a pity that installation problems get somewhat often in the way of their usage.

Also, as far as I understand there are not very many good (easier to use) options either. The only possibly easier solution for you I know about is the "Yet Another Matrix Module" (see NumericAndScientific/Libraries listing on python.org). I am not aware of the status of this library (stability, speed, etc.). The possibility is that in the long run your needs will outgrow any simple library and you will end up installing numpy anyway.

Another notable downside on using any other library is that your code will potentially be incompatible with numpy, which happens to be the de facto library for linear algebra in python. Note also that numpy has been heavily optimized - speed is something you are not guaranteed to get with other libraries.

I would really just put more effort on solving the installation/setup problems. The alternatives are potentially much worse.

jsalonen
  • 29,593
  • 15
  • 91
  • 109
  • Been there as well. There are far too many points where Python+Windows suck together. – jsalonen Nov 29 '11 at 18:53
  • 2
    Been using python+windows all the time - never had problems. Something about this numpy/scipy combo is really messing it up. – Andriy Drozdyuk Nov 29 '11 at 19:00
  • 2
    I have to disagree. If Python works on Windows like a charm, then why in Python documentation there is a complete chapter full of FAQ for Windows (and none for other OSes)? http://docs.python.org/faq/windows.html – jsalonen Nov 29 '11 at 19:13
  • Python+Numpy+Scipy+... on Windows just work perfect. Never had any problem. – Developer Dec 15 '12 at 03:52
  • 2
    Anaconda is the perfect way around for installing numpy and scipy on windows. https://www.continuum.io/downloads – JackOrJones Feb 28 '16 at 20:10
2

Given your question, I decided just factor out the matrix code from where I were using it, and put it in a publicly accessible place -

So, this is basically a pure python ad-hoc implementation of a Matrix class which can perform addition, multiplication, matrix determinant and matrix inversion - should be of some use -

Since it is in pure python, and not worried with performance at all it unsuitable for any real calculation - but it is good enough for playing around with matrices in an interactive way, or where matrix algebra is far from being the critical part of the code.

The repository is here, https://bitbucket.org/jsbueno/toymatrix/

And you can download it straight from here: https://bitbucket.org/jsbueno/toymatrix/downloads/toymatrix_0.1.tar.gz

jsbueno
  • 99,910
  • 10
  • 151
  • 209
1

Have you ever tried anaconda? https://www.anaconda.com/download This should allow it to install those packages easily.

conda install -c conda-forge scipy

conda install -c conda-forge numpy

Apart from offering you an easy way to install them in linux/mac/linux you will get virtualenviroments management too

Cesc
  • 904
  • 1
  • 9
  • 17
0

For people who still have the problem: Try python portable: http://portablepython.com/wiki/Download/

0

Have a look: tinynumpy, tinyarray and sympy

  1. https://github.com/wadetb/tinynumpy
  2. https://github.com/kwant-project/tinyarray
  3. https://docs.sympy.org/latest/index.html
Jaja
  • 662
  • 7
  • 15
0

I sometimes have this problem..not sure if this works but I often install it using my own account then try to run it in an IDE(komodo in my case) and it doesn't work. Like your issue it says it cannot find it. The way I solve this is to use sudo -i to get into root and then install it from there.

If that does not work can you update your answer to provide a bit more info about the type of system your using(linux, mac, windows), version of python/numpy and how your accessing it so it'll be easier to help.

Lostsoul
  • 25,013
  • 48
  • 144
  • 239