0

Suppose the following code:

x = np.array([3,2])
y = [x,x]
z = np.array(y)

now z has two different copies of x which are different from the original x as well:

x[0] = 10

y

[array([10, 2]), array([10, 2])]

z

array([[3, 2], [3, 2]])

I need to save memory by just make z contains references to x not a copy of it, how to do it in numPy?

ammcom
  • 992
  • 1
  • 7
  • 24
  • If you want read-only copies, use `np.broadcast_to`. – cs95 Jun 03 '19 at 02:13
  • Is the [x,x] duplicate meaningful, or just part of the example? How about `np.array([x,y,z])`? – hpaulj Jun 03 '19 at 02:33
  • 1
    An object dtype array can contain arrays (or other objects) in basically the same ways as a list does. Math operations are slower, if they work at all. – hpaulj Jun 03 '19 at 02:43

0 Answers0