-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
fix error: 'numpy.ndarray' object has no attribute 'append' #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix error: 'numpy.ndarray' object has no attribute 'append' #662
Conversation
fix error: 'numpy.ndarray' object has no attribute 'append'
| if (pol_x[0] != pol_x[-1]) or (pol_y[0] != pol_y[-1]): | ||
| pol_x.append(pol_x[0]) | ||
| pol_y.append(pol_y[0]) | ||
| np.append(pol_x, pol_x[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR. is it possible to add a test for this change in this file? https://github.com/AtsushiSakai/PythonRobotics/blob/master/tests/test_grid_map_lib.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After my survey, the error occurs in grid_based_sweep_coverage_path_planner.py because the function convert_grid_coordinate returns numpy.ndarray. I think it more suitable to modify grid_based_sweep_coverage_path_planner.py:
from
def convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position):
tx = [ix - sweep_start_position[0] for ix in ox]
ty = [iy - sweep_start_position[1] for iy in oy]
th = math.atan2(sweep_vec[1], sweep_vec[0])
rot = Rot.from_euler('z', th).as_matrix()[0:2, 0:2]
converted_xy = np.stack([tx, ty]).T @ rot
return converted_xy[:, 0], converted_xy[:, 1]to
def convert_grid_coordinate(ox, oy, sweep_vec, sweep_start_position):
tx = [ix - sweep_start_position[0] for ix in ox]
ty = [iy - sweep_start_position[1] for iy in oy]
th = math.atan2(sweep_vec[1], sweep_vec[0])
rot = Rot.from_euler('z', th).as_matrix()[0:2, 0:2]
converted_xy = np.stack([tx, ty]).T @ rot
return converted_xy[:, 0].tolist(), converted_xy[:, 1].tolist()In this case, we do not need to change the algorithm file and the pytest file. What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to use np.array instead of build-in list in codes. So I love this PR change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. I think test should be add to https://github.com/AtsushiSakai/PythonRobotics/blob/master/tests/test_grid_based_sweep_coverage_path_planner.py because in https://github.com/AtsushiSakai/PythonRobotics/blob/master/tests/test_grid_map_lib.py, ox[0] != ox[-1] and oy[0]!=oy[-1] make np.append effective.
def test_polygon_set():
ox = [0.0, 20.0, 50.0, 100.0, 130.0, 40.0]
oy = [0.0, -20.0, 0.0, 30.0, 60.0, 80.0]
grid_map = GridMap(600, 290, 0.7, 60.0, 30.5)
grid_map.set_value_from_polygon(ox, oy, 1.0, inside=False)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test. So LGTM. thank you!!
Reference issue
fix error: 'numpy.ndarray' object has no attribute 'append'
What does this implement/fix?
When running
grid_based_sweep_coverage_path_planner.pyand givingoxandoywithoutox[0] == ox[-1], you will getfix error: 'numpy.ndarray' object has no attribute 'append'Additional information
CheckList
-[] Did you add an unittest for your new example or defect fix?
-[] Did you add documents for your new example?
-[] All CIs are green? (You can check it after submitting)