In my Numpy / Pandas lesson I am taught to make data with the following code:
sample_numpy_data = np.array(np.arange(24)).reshape((6,4))
Isn't it redundant to use np.array() on the np.arange() as np.arange() already produces an array?
Why is this necessary? example?
Example found in Lynda course "Pandas for Data Science" Pandas Overview - Operations.
答案 0 :(得分:5)
It is not only redundant, it also introduces unnecessary overhead because it makes a copy of the array by default.
If you're not sure if something is an array (maybe because it's an argument for a function) you can use np.asarray
on it. That only copies if it's not an array.