I have two variables, x and y. x is
type(x) = <class 'numpy.matrixlib.defmatrix.matrix'>
type(y) = <type 'numpy.ndarray'>
x.shape = (869250, 1)
y.shape = (869250,)
x+y gives a MemoryError, despite the fact that I have around 5 gb free. This seems rather odd – does anyone have an idea as to what might be going on?
This is numpy 1.5.1, python 2.7, on 64 bit Linux.
Are you sure you’re doing what you want to be doing?
This is a somewhat unintuitive application of numpy’s broadcasting rules. Your result is actually going to be
869250 x 869250, for a total of 5.5 terabytes of storage in the probably-defaultnp.float64.You more likely to want the vector sum. If you want to keep
xas amatrix(which is often confusing, but…), you could do something likex + y.reshape(-1, 1).