The error is generated by the below source code:
OP_REQUIRES(context, axis >= 0 && axis < input_dims, errors::InvalidArgument("Expected dimension in the range [", -input_dims, ", ", input_dims, "), but got ", dim));
Here, axis should be less than input_dims, not less-than-or-equal.
[-1,1) in the error message shows that ‘[’ indicates an inclusive value such that -1 is valid and ‘)’ indicates an exclusive value.
If you wish to learn more about how to use python for data science, then go through data science python programming course by Intellipaat for more insights.