1

Given the following array:

import numpy as np
G = np.array([[2.7, 0, -0.2, 0, -0.5, -1],
                  [0, 9, 0, 0, -10, 1],
                  [-0.2, 0, 4.2, -4, 0, 0],
                  [0, 0, -4, 4, 0, 0],
                  [-1.5, -10, 0, 10.5, 0],
                  [-3, 1, 0, 0, 0, 1]])

If i remove a row from the array using G = np.delete(G, 3, axis=0), it removes row at position 3 properly.

But i cannot remove a column like this: G = np.delete(G, 3, axis=1)

I get following error:

numpy.AxisError: axis 1 is out of bounds for array of dimension 1.

Can someone please point me to the right way? what am i doing wrong ?

3
  • 6
    Your array is broken. The row lengths don't match; [-0.5, -10, 0, 10.5, 0] only has 5 elements. Commented Feb 20, 2019 at 18:06
  • Did you look at G after creating it? Does it look like a normal 2d numeric array? Commented Feb 20, 2019 at 18:09
  • @user2357112 you are right thanks. Commented Feb 20, 2019 at 18:11

1 Answer 1

1

Your array has shape of (6,) because your array lengths don't match. Check the second to last array. If you only have 5 observations, add np.nan to the end of row 5 (like this [-1.5, -10, 0, 10.5, 0,np.nan],and you'll fix the problem.

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

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.