0

Can someone please explain this code to me

case = np.array([[1,2], [2,4], [3,5]]) 

I understand the above gives 2 columns and 3 rows.

But the code below I don't understand. Please help me to understand it.

np.arange(0, case.shape[0]+4)
2
  • case.shape is (2,3), case.shape[0] is 2, so the code is just np.arange(6). Commented May 21, 2020 at 13:23
  • @QuangHoang. Aside from the shape being (3, 2), you are absolutely correct Commented May 21, 2020 at 20:16

2 Answers 2

1

np.arange() returns evenly spaced values within a given interval.

In this case, since case.shape[0] is the first axis of the array, which has 3 arrays in it, the range goes from 0 to 3+4=7 (end not included).

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

Comments

0
case = np.array([[1,2], [2,4], [3,5]])
case
array([[1, 2],
   [2, 4],
   [3, 5]])

Numpy.arange will provide a series of numbers starts from 0 to case.shape[0] +4 . Here case.shape is (3,2) (Three Rows and Two Columns) . So Case[0] will be 3 and case[1] will be 2 . So np.arrange will be a series of numbers from 0 to 3+4 = 7 where 0 is included and 7 is excluded and output will be 0,1,2,3,4,5,6

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.