FW: using numpy

Hi,

This is a piece of code in my project I need help and
clarification on.

fg = gr.flow_graph()

mult1 = gr.multiply_ff()
fg.connect(src, (mult1, 0))
fg.connect(cos_wav, (mult1, 1))

gate_I = gr.vector_sink_f()
fg.connect (mult1, gate_I)

I_data = numpy.array(gate_I.data())

I am using numpy.array to get an array on which I need to do some
operations like sum() etc. If I am executing this code in the pycrust
interpreter line by line, I am able to get the data in I_data. But when
I write the same code in a .py file and execute, I am not getting any
data.

Even if I copy these set of lines and execute in pycrust using the
‘paste plus’ option, this doesn’t workout.

In my code, I need to convert a gr.float vector to an numpy array and
the array (or list) back to gr.float vector (using
gr.vector_source_f()). Please let me know why this problems happen and
the precautions to be taken while doing such data type conversions.

Thanks a lot.
Regards,
N Sivaram

You need to start the flow graph, let it run for a few
seconds/milliseconds, then get the data.

Try making these changes:

import time

fg = gr.top_block()

mult1 = gr.multiply_ff()
fg.connect(src, (mult1, 0))
fg.connect(cos_wav, (mult1, 1))

gate_I = gr.vector_sink_f()
fg.connect (mult1, gate_I)

fg.start()
time.sleep(XXX) #enough time to collect data
fg.stop()

I_data = numpy.array(gate_I.data())

-Josh

On Thu, Aug 14, 2008 at 06:54:59AM -0700, Josh B. wrote:

fg.connect(src, (mult1, 0))

Like Josh said, or possibly better yet, add a gr.head and use fg.run
to collect exactly the number of samples that you want.

Eric

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs