Efficient way to work with 2D Arrays (multiple formats)


Efficient way to work with 2D Arrays (multiple formats)



I have an efficiency/performance question in Python:



I am planning to store data in some kind of matrix format in a "storage"



For example:
elementID - nodeID - elementType - Value



My current process is to loop through the raw data information and check if there is already an entry with "elementID, nodeID, elementType" in the storage.



Now, when considering a second case, also a second value is occuring. What I want to do is now to add the second value to the associated case in the storage.
So:
elementID - nodeID - elementType - Value1 - Value2



Currently I am working with 2D arrays, so [[a,b,c],[b,c,d],....].
Since this is implying "for loops", the time required to check if the entry is already in the storage is increasing tremendously. Also to add the additional column to the storage is requiring the search for the corresponding entry.



In some cases, it is also possible that there are many value columns. My next step would be to get the maximum of all value columns for each elementID-nodeID etc.



A possibility would be to make a numpy matrix out of it. By this approach, the maximum can be comparably easy calculated. However, as far as I know, it is not easy to combine different formats in a numpy matrix, am I right here?



What would be an adequate solution to this? (regarding performance)



Thanks a lot!



Benny





1.: You don't need python loops with numpy in like 99.999% of cases. 2.: A small piece of code and an example would help tremendously.
– Scotty1-
2 days ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift