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

2
  • I believe what you suggest should work: x = numpy.array([1,2,3]) ; y1=x Commented Jan 29, 2019 at 10:28
  • Duplicate of stackoverflow.com/questions/5951135/… Commented Jan 29, 2019 at 10:34

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the answer, my intention is to use expression y=x or y = 2x like that
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.