Nengo Import File

Dear community,

I am Yu from ECE department TUM. I am using the nengo framework.

How can I import file into Nengo?

Sincerely

Hi @yuwang90, and welcome to the Nengo forums! :smiley:

Regarding your question:

Can you elaborate on what you want to achieve? Are you looking to import data from a file and have that fed into a Nengo network? Or… are you wanting to import your own Python package into Nengo?

Yes, Sir.

I am looking how can I import data from a file and have that fed into a Nengo network.

Any example would be great!

If you want to import data from a file and feed it into a Nengo network, you’ll want to use the nengo.Node to do that. The Nengo node accepts any arbitrary Python code and runs it every timestep of the Nengo simulation. Here’s an example of how a node is used within a Nengo network: Delaying a connection with a node — Nengo 3.2.1.dev0 docs

In your case, you’ll want to write the Python code that parses the file data, and use that in the Nengo node. Note that you don’t have to load the file data from within the Nengo node itself, you can load the data to memory (outside the Nengo network) and then in the node’s function, just load the data from memory. Something like this:

# Import data to memory
def load_from_file():
    ... # Parse file, load data into memory
    return data

dt = 0.001  # Define dt to figure out data index

# Nengo node function
def get_data(t):
    return data[int(t / dt)]

# Nengo network
with nengo.Network() as model:
    inp = nengo.Node(get_data)
    .... # Rest of model