Remove last element in python numpy array

Viewed 19

Hi I am trying to create a new array as a subset from this array where I don't need the last element. Is there a way I could slice based on this shape of the array? Basically I will want to discard the following numbers (e.g. 0.028524462,0.008772644,-0.020015412 .....)

array([[0.035753707999999995, 0.038376187, -0.004679315, 0.002193419,
        0.0038943759999999997, 0.0, 0.031190229, 0.012698039,
        0.028524462],
       [0.025425872999999998, 0.031812743, 0.0077867380000000005,
        0.008455341, 0.012865611, 0.0041624520000000005, 0.01891958,
        0.011340652, 0.008772644],
       [-0.02886173, -0.026352966000000002, -0.030469134, -0.017833062,
        -0.028734593, 0.017292932, -0.035898576, -0.017072795,
        -0.020015412],
       [-0.062208079000000006, -0.084715902, 0.0033913640000000004,
        -0.011726277, -0.00046599900000000004, -0.040061308999999996,
        0.028283152000000002, -0.005560959, -0.019423778],
       [0.009859905, 0.009658112, -0.021533207999999998, -0.019872754,
        -0.012709716999999999, -0.004473502, -0.00976388,
        -0.010988633999999999, -0.007802211999999999]], dtype=object)
1 Answers

You can slice it:

a[:,:-1]

Output:

array([[0.035753707999999995, 0.038376187, -0.004679315, 0.002193419,
        0.0038943759999999997, 0.0, 0.031190229, 0.012698039],
       [0.025425872999999998, 0.031812743, 0.0077867380000000005,
        0.008455341, 0.012865611, 0.0041624520000000005, 0.01891958,
        0.011340652],
       [-0.02886173, -0.026352966000000002, -0.030469134, -0.017833062,
        -0.028734593, 0.017292932, -0.035898576, -0.017072795],
       [-0.062208079000000006, -0.084715902, 0.0033913640000000004,
        -0.011726277, -0.00046599900000000004, -0.040061308999999996,
        0.028283152000000002, -0.005560959],
       [0.009859905, 0.009658112, -0.021533207999999998, -0.019872754,
        -0.012709716999999999, -0.004473502, -0.00976388,
        -0.010988633999999999]], dtype=object)
Related