B_Furtado B_Furtado - 3 months ago 9
Python Question

What is the equivalent of list when using numpy?

When I want to copy a list without linking to the same object I have to call list. So:

a = [1, 2, 3]
b = list(a)

a == b
True

a is b
False


What would be the equivalent when I have a numpy array

import numpy
a = numpy.ones(4)

b = XXX(a)?


Thanks in advance

Answer

Use the copy-method:

b = a.copy()
Comments