ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

publish numpy matrix to topic

asked 2016-08-01 09:03:31 -0600

Bant gravatar image

Hello together,

I would like to publish a 10x10x10 numpy-Matrix in one publishing step. Therefore I would like to know how I can declare the numpy.ndarray as a message type like


numpy.ndarray matrix

Is that even possible? What do I have to add to the CMakeLists.txt to get that running? Is there maybe a better way?

Thanks in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-08-01 12:34:17 -0600

emielke gravatar image

I've tried this before, the simplest way I could find was to put the matrix into row-major order and publish the data as an array. In essence, I just used the Float64MultiArray msg type and filled up that array with the matrix information and then published it. I don't know if there is a way to make a "matrix" msg type that would make this more simple, but this worked for me and I was able to get all the info passed around pretty easily.

edit flag offensive delete link more


Even though I posted the numpy tutorial I do agree that this might be the easiest solution.

Chrissi gravatar image Chrissi  ( 2016-08-01 13:25:36 -0600 )edit

Thank you. I will do it like this for now. If I find a different approach I will add an answer here.

Bant gravatar image Bant  ( 2016-08-02 04:43:41 -0600 )edit

answered 2016-08-01 09:42:32 -0600

Chrissi gravatar image

The ros numpy tutorial might help.

edit flag offensive delete link more


I think the tutorial only covers arrays, as they are using the "Floats" msg from rospy_tutorials. (Floats.msg: float32[] data)

Bant gravatar image Bant  ( 2016-08-02 04:45:55 -0600 )edit

Question Tools

1 follower


Asked: 2016-08-01 09:03:31 -0600

Seen: 1,505 times

Last updated: Aug 01 '16