asarray(x)
is like array(x, copy=False)
Use asarray(x)
when you want to ensure that x
will be an array before any other operations are done. If x
is already an array then no copy would be done. It would not cause a redundant performance hit.
Here is an example of a function that ensure x
is converted into an array first.
def mysum(x):
return np.asarray(x).sum()