1

I am trying to follow along on a video tutorial of numpy and the array is created in the video as follows

a = np.array([[1,2,3,4,5,6,7],[9,10,11,12,13,14]])

when I do this, I get the output

[list([1, 2, 3, 4, 5, 6, 7]) list([9, 10, 11, 12, 13, 14])]

in the video, the output does not look like this and I cannot find a difference in our code. The output in the video looks like a normal 2D numpy array with 7 columns and 2 rows.

also, when I do a.shape() I get a (2,) array which is not a 2 by 7 array, which is what he has in the video. I have tried np.asarray() and different combinations of brackets and parenthesis, I am just confused because my code is exactly the same as the video. The video is less than a year old so I assume nothing has changed with the package? Any help is appreciated, I am hoping to turn this into a learning experience on how to solve problems like this by myself in the future. Thank you.

2 Answers 2

1

Your second list only has 6 elements so numpy cannot parse it as a 2D array; instead it parses it as a 1D array of object type, and these objects are lists

a = np.array([[1, 2, 3, 4, 5, 6, 7],[9, 10, 11, 12, 13, 14, 15]])

works fine

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

1 Comment

I see , they both have to be the same length then. Thank you for quick response
0

Are you the code in the video was not

a = np.array([[1,2,3,4,5,6,7],[8,9,10,11,12,13,14]])

which works as expected. Notice the 8 at the beginning of the second list, this was missing in your code, which meant that the two lists were different sizes, hence numpy fails to make a float array out of it.

1 Comment

I will double check in a moment, it is definitely possible I just made a typo. Thank you for the help.

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.