# Upload numpy array on pynq dram

**URL:** https://discuss.pynq.io/t/upload-numpy-array-on-pynq-dram/5257
**Category:** Support
**Created:** [February 23, 2023, 1:02pm UTC](https://discuss.pynq.io/t/upload-numpy-array-on-pynq-dram/5257 "2023-02-23T13:02:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fkj1196](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@fkj1196](https://discuss.pynq.io/u/fkj1196)
#### Post date: [February 23, 2023, 1:02pm UTC](https://discuss.pynq.io/t/upload-numpy-array-on-pynq-dram/5257/1 "2023-02-23T13:02:54Z")

</div>

- board : pynq z1

I have a file “input.npy” which have size of 100x100, and type of np.float32.

this file can be uploaded on dram using buffer write like below.

```auto
input_file = np.load('input.npy')
input_dram = allocate(shape=(100, 100), dtype=np.float32)
for i in range(100):
   for j in range(100):
      input_dram[i][j] = input_file[i][j]

```

However, this way takes a lot of time if data size gets bigger.

I must use attribute “physical\_address” in pynq.buffer.

These two ways delete “physical\_address” of “input\_dram” when executed.

```auto
# way 1
input_dram = allocate(shape=(100, 100), dtype=np.float32)
input_dram = np.load('input.npy')

```

```auto
# way 2
input_file = np.load('input.npy')
input_dram = allocate(shape=(100, 100), dtype=np.float32)
input_dram = input_file.copy()

```

When printing physical address, the error message said AttributeError: ‘numpy.ndarray’ object has no attribute ‘physical\_address’

Is there another way directly upload numpy file on pynq dram?

---

<div class="post-metadata">

### Author: ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)
#### Post date: [February 23, 2023, 1:44pm UTC](https://discuss.pynq.io/t/upload-numpy-array-on-pynq-dram/5257/2 "2023-02-23T13:44:35Z")

</div>

Hi @fkj1196,

It takes a lot of time because you are coping element by element.

Code snipped below will overwrite the whole `input_dram` array, so avoid doing this (this is why you get the attribute error)

```python
input_dram = input_file.copy()

```

You can simply do:

```python
input_dram[:] = input_file

```

This will copy your `input_file` object contents to the allocated array.

Mario

---

<div class="post-metadata">

### Author: ![fkj1196](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@fkj1196](https://discuss.pynq.io/u/fkj1196)
#### Post date: [February 23, 2023, 1:57pm UTC](https://discuss.pynq.io/t/upload-numpy-array-on-pynq-dram/5257/3 "2023-02-23T13:57:57Z")

</div>

This works very fast.

Appreciate for your answer.

---

<div class="post-metadata">

### Author: ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)
#### Post date: [February 23, 2023, 2:09pm UTC](https://discuss.pynq.io/t/upload-numpy-array-on-pynq-dram/5257/4 "2023-02-23T14:09:09Z")

</div>


