# getting Index Error while accessing numpy array values using slicing [closed]

import numpy as np
demo_matrix=np.array(([13,35.74,48],[23,37,37,38],[73,39,93,39]))

demo_matrix[2,3]


I'm getting Index Error when I tried to run this code.
Can anyone help?

• Hello and welcome to Data Science Stack Exchange. Your question is far from respecting the rules to be accepted on the website. Check ThisLink to understand how to ask a question here – BeamsAdept Sep 18 at 9:15

There are two ways to correct this

1. you passed three lists to np.array, and there are not all same size

demo_matrix = np.array(([13,35,74,48],[23,37,37,38],[73,39,93,39]))

demo_matrix[2,3]
#demo_matrix (list of lists)
array([[13, 35, 74, 48],
[23, 37, 37, 38],
[73, 39, 93, 39]])


you used 35.74, I guess it might be typing mistake

1. If you think you are passing list values correctly use below code

demo_matrix[2][3]

if passed lists have different sizes then output array will be array of lists

array([list([13, 35.74, 48]), list([23, 37, 37, 38]),
list([73, 39, 93, 39])], dtype=object)

• Understood. Thanks! – Kenil Sep 18 at 9:46
• I am glad it helped you. So can accept the answer? – Divya reddy Sep 18 at 9:54