Rework ndarray

Ready for review!

I passed memcheck on the test_numpy part, and it seems OK.