From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending and receiving arrays with python in labview

Hi,

So my end goal is to use a python script in a while loop to modify arrays of data (1400x1000) in real time.

 

For now however, I'm just trying to make a simple array addition using python. If you look at my example, instead of making an addition, python simply puts the two vectors after one another. It works fine however if I use it with other software.

 

From what I read, Python converts the arrays from labview into lists. You can use the numpy.array function to turn them back into arrays in python. Howver, I'm not sure how to get the return y. The code gives me a <class 'SystemError'> if I do this. (Second test1 file) I imagine I need to turn back the python arrays into python list?

 

Also isn't this very inefficient?

Thank you.

Download All
0 Kudos
Message 1 of 9
(6,783 Views)

I have not had any experience with running python in LabVIEW and I can't see your code on this machine, so I will ask a more fundamental question: What kind of array manipulations do you want to perform? Is there a reason why you don't want to do this in LV? In Place structures are quite handy for efficiently modifying elements of an array in LV.

 

I could understand if you wanted to use some funny functions from a .py module to do, say, image manipulations. Let us know what you plan to do.

CLA - Kudos is how we show our appreciation for comments that helped us!
Message 2 of 9
(6,747 Views)

I have multiple manipulations to do to my arrays. They are all doable on Labview but rather difficult to do. It's a lot easier to do with written code and functions.

 

For example, make a 3D convoluation followed by multiple multiplaction addition and division. Then, index the values in the arrays depending of the its value. I am indexing the data so I associate them another value depending between which range they are.

 

All of this become rather complicate to write in Labview and I doubt that Labview is well optimize for it.

0 Kudos
Message 3 of 9
(6,729 Views)

@RaphaelMT wrote:

I have multiple manipulations to do to my arrays. They are all doable on Labview but rather difficult to do. It's a lot easier to do with written code and functions.

 

For example, make a 3D convoluation followed by multiple multiplaction addition and division. Then, index the values in the arrays depending of the its value. I am indexing the data so I associate them another value depending between which range they are.

 

All of this become rather complicate to write in Labview and I doubt that Labview is well optimize for it.


You do know LV is used e.g. at CERN? I'd rather question how well optimized Python is for the task, but when all you have is a hammer, everything looks like a nail.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 9
(6,724 Views)

For this kind of work I would use Matlab, which has some great array-based indexing, including logical indexing. If I had to do with within the LV environment I would use a mathscript node.

 

I have problems with doing this sort of thing in python, which does not seem to be as well equiped for array manipulations (hence the existance of numpy and numpy.arrays particularly.

 

Each language tends to be optimised for certain types of problems. I found my problems with python started melting away when I stopped trying to treat it like matlab (array based thinking) and embraced doing everything elementwise, much like C!

CLA - Kudos is how we show our appreciation for comments that helped us!
Message 5 of 9
(6,720 Views)

I actually used Matlab for my proof of concept, but from what I read it is very slow to transfer variables from labview to matlab and back. I need to run the whole code in 0.1 second max.

0 Kudos
Message 6 of 9
(6,709 Views)

I am not sure about delays in transferring variables. I guess the variable in question is a large array of doubles, which could take some significant memory and be relatively slow to operate on. But the thing to do is to benchmark the process or processes involved to see if any are really critically slow.

 

You might hear a lot of rumours about performance of languages in certain situations, but usually it is faster overall (development time + running time) to simply program in something you are familiar with! It is worthwhile making a quick benchmark that just transfers the variable into the mathscript node, put it in a while loop and run it 1000x with a get current time (ms) node before and after. Ensure timing by using a flat sequence structure. Let us know the results!

CLA - Kudos is how we show our appreciation for comments that helped us!
Message 7 of 9
(6,698 Views)

any solution for this issue.i am also getting same error

0 Kudos
Message 8 of 9
(5,593 Views)

I abandoned using python after learning I needed to re-import all my functions each time I called the python node.

0 Kudos
Message 9 of 9
(5,582 Views)