-3
$\begingroup$
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?

Thanks in advance

$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – BeamsAdept Sep 18 at 9:15
1
$\begingroup$

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)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Understood. Thanks! $\endgroup$ – Kenil Sep 18 at 9:46
  • $\begingroup$ I am glad it helped you. So can accept the answer? $\endgroup$ – Divya reddy Sep 18 at 9:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.