0

Let's say that I already have a list that I created and assigned to a variable.

example = [1, 2, 3, 4]

Then later on in my code I want to convert this to an array. Which of these is better practice?

example = np.array(example)
#or
example = np.asarray(example)

Or is there another way that's even better?

  • `asarray` calls the `array` constructor anyways, but `asarray` will not copy by default unless it has to. – user3483203 Jul 30 '18 at 18:20
  • Use the obvious, `np.array`. In a general purpose function that should accept an an array as well as a list, then `asarray` may save a smidgen of time. – hpaulj Jul 30 '18 at 19:20
  • @user3483203 I already read that thread and I know the difference, but when I'm converting a predefined list to an array and I won't need the old list anymore, is it better to create the copy using .array() or is it better to use .asarray()? –  Jul 30 '18 at 19:35

0 Answers0