0

how can I create an np array using expression y1 = x, when x array is already defined

x = [1,2,5,7]

from this array x , I would like to create another array y1 using the expression

y1 = x

using numpy

Parthi
  • 135
  • 4
  • 14

1 Answers1

1

If you want a copy of the array it would be

import numpy as np
y1 = np.array(x)

Currently you just assign the list from x to y1. With this you create a new numpy array with the values from x.

Syrius
  • 941
  • 6
  • 22
  • thanks for the answer, my intention is to use expression y=x or y = 2x like that – Parthi Jan 29 '19 at 10:32
  • Then you need to set x = np.array([1,2,5,7]). Than you can just put y = x or y=2x or whatever you want. But in this case x has to be a numpy array – Syrius Jan 29 '19 at 10:35