0

So I have 4 variables that show coordinates x and y/

e.g:

first_co = [0,0]
second_co = [100,200]
third_co = [300,400]
fourth_co = [800,1000]

When i tried to just declare a numpy array as

box = np.array([first_co],[second_co],[third_co],[fourth_co])

I got a value error, how do I declare a numpy array with 4 variables?

0

2 Answers 2

2

You need to feed a (nested) list of lists to np.array:

box = np.array([first_co, second_co, third_co, fourth_co])

box.dtype  # dtype('int32')

Result:

array([[   0,    0],
       [ 100,  200],
       [ 300,  400],
       [ 800, 1000]])

The docs make this clear:

object : array_like

An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence.

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

Comments

0

Maybe this is what you want:

box = np.array([first_co,second_co,third_co,fourth_co])

Comments

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.