How to insert vector shape in a buffer using PYNQ board Z1

Hello, I am new to the PYNQ board and I am following a tutorial to send data to the PYNQ board.

In the tutorial, it has initialized random number to insert into the input buffer as an input but I want to initialize a 300 cross-sectional vector Vector1 =[1,2,3…300] into an input buffer. But not sure how can I do that? Here it few lines of code.

from pynq import Overlay
ol = Overlay("./dma_tutorial.bit")
dma = ol.axi_dma
dma_send = ol.axi_dma.sendchannel
dma_recv = ol.axi_dma.recvchannel
from pynq import allocate
import numpy as np
data_size = 300
input_buffer = allocate(shape=(data_size,), dtype=np.uint32)

Initialize the buffer with random values

for i in range(data_size):
    input_buffer[i] = i + 0xcafe0000

Please guide me how can I change the buffer initial values into a real vector values?

Hi @Abdul_Wahab,

pynq.allocate returns a pynq.Buffer. This buffer is a numpy array for use with other Python libraries. Any array that you can generate with numpy can be used to fill the pynq.Buffer.

So, you can assign a numpy array to the input_buffer, for instance the code below will generate integers from 0 to 299

 input_buffer[:] = numpy.arange(0, 300, dtype=numpy.uint32)

You should be able to find plenty of documentation about numpy on the web.


1 Like