Tamjeed Anees
Tamjeed Anees

Reputation: 81

Is there any way to get rid of the zero-size array reduction error?

back_vec = np.array([(joint[4].x - joint[3].x, joint[4].y - joint[3].y) for joint in joints])
back_vec_range = np.max(back_vec, axis=0) - np.min(back_vec, axis=0)

When I am running the program containing the following code. I am getting the Zero-Array reduction error again and again but I am unable to fix the error. Kindly help me out. The respective error is given below:

Traceback (most recent call last):
  File "main.py", line 81, in <module>
    main()
  File "main.py", line 50, in main
    (correct, feedback) = evaluate_pose(pose_seq, args.exercise)
  File "D:\Techolon\pose-trainer\evaluate.py", line 19, in evaluate_pose
    return _shoulder_press(pose_seq)
  File "D:\Techolon\pose-trainer\evaluate.py", line 215, in _shoulder_press
    back_vec_range = np.max(back_vec, axis=0) - np.min(back_vec, axis=0)
  File "C:\Users\Tamjeed Anees\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", line 2505, in amax
    initial=initial)
  File "C:\Users\Tamjeed Anees\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation maximum which has no identity

Upvotes: 1

Views: 821

Answers (1)

tstanisl
tstanisl

Reputation: 14107

I think that you should not perform any computation if joints is empty ... but if you really really want to do it you can pass argument initial to np.max(). I suggest setting it to the lowest possible value like minus infinity.

x.max(axis=0, initial=-np.inf)

Upvotes: 2

Related Questions