473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

speed up data extraction from large arrays

2 New Member
hi,

I have three arrays with variable values from a netCDF file. xy contains the vectors for the lon and lat coordinates. I am extracting the coordinates out of the two arrays (lon, lat) according to the vectors in the xy array. So far, I get the correct results, but the speed of the extraction process (for-loop) is extremely poor!!

Here's my code:

Expand|Select|Wrap|Line Numbers
  1. from netCDF4 import Dataset
  2. import scipy as scp
  3. import numpy as np
  4.  
  5. # open netCDF file and create a dataset
  6. rootfile = "myfile.nc"
  7. rootgrp = Dataset(rootfile, "r")
  8.  
  9. # read variable values into arrays
  10. xy = rootgrp.variables["zipxy"]
  11. lon = rootgrp.variables["lon"]
  12. lat = rootgrp.variables["lat"]
  13.  
  14. # create a new coordinates array
  15. coordinates = np.array([[],[]])
  16.  
  17. # loop through the xy array and write the corresponding lon & lat coordinates
  18. # into the coordinates array
  19. # NOTE: the vectors in xy begin with [1,1] BUT the index of the values
  20. # in lon & lat begins with [0,0] -> therefore: y-1, x-1
  21. for x, y in xy:
  22.     coordinates = np.append(coordinates,[[lon[y-1,x-1]],[lat[y-1,x-1]]],1)
  23.  
The dimensions are:
xaxis = 1320
yaxis = 1482
zip2 = 1080236

And the shape of the variables:
zipxy('zip2', 'two')
lon('yaxis', 'xaxis')
lat('yaxis', 'xaxis')

There must be a way to speed up the coordinate extraction (maybe I need another searching method through the arrays...). Until now, I couldn't find any solution.

Thanks for help!
Mar 23 '11 #1
3 2711
Mariostg
332 Contributor
You should have a read at Python Patterns - An Optimization Anecdote
. That shall inspire you.
Mar 23 '11 #2
dwblas
626 Recognized Expert Contributor
A list/array is slow. Consider using a set or dictionary as they are hashed. It you just want all of the coordinates, a set made up of tuples=(x, y) or ([lat_x, lat_y], [lon_x, lon_y]) will work fine. Your time consumer is probably the lookups here so time the read/create arrays and the for loop separately so you know where the problem is.
Expand|Select|Wrap|Line Numbers
  1. # for x, y in xy:
  2. #     coordinates = np.append(coordinates,[[lon[y-1,x-1]],[lat[y-1,x-1]]],1)
Mar 23 '11 #3
blackdevil
2 New Member
Thanks a lot for the both answers!
I will try some possibilities and post the results
Mar 24 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4842
by: Steven James Samuel Stapleton | last post by:
Will calling ksort() on an array speed up it's access? For example, I have the array $file_index, which is accessed by a key (the entry id) and has two sub elements in a one dimensional array (line number of the start of the entry in the file, and the byte offset of the start of the entry). so, I might have an array that can be represented thus: {
2
1417
by: matthew.weiner | last post by:
I have a bunch of SPs that all rely on a UDF that parses a comma delimitted list of numbers into a table. Everything was working fine, but now my application is growing and I'm starting to approach the 8000 character limit of the varChar variable used to store the list. I would like to change the UDF only and avoid having to dig through all of my stored procedures. I was hoping to use the text datatype to allow for much larger lists,...
19
3460
by: Hal Styli | last post by:
Hello, Can someone please help. I need to use a large array and I'm not sure when one should use (A) and when one should use (B) below:- #define MAX 10000000 (A) int x;
1
1928
by: Jason Huang | last post by:
Hi, To make it short, how do we do the data extraction to MSWord using ASP.Net C#? Any help will be appreciated. Jason
2
2971
by: Jason Huang | last post by:
Hi, Would someone show me how to do the data extraction to Excel in ASP.Net using C# web form? I am not familiar with VB, so I am asking someone to help me out! Any help will be appreciated. Jason
0
1009
by: Alastair Alexander | last post by:
Hi ... I'm using pythoncom to create a python COM server application that needs to be able to return large arrays to COM client apps. For example, I need to be able to return an array to Excel that is 500 by 10, with each element of the array holding a 32 byte string. If I run the code for smaller arrays, say 10 by 10, it works fine. If I allow the server to try to return the entire 500 by 10 array, pythonw.exe causes a memory access...
10
5885
by: Peter Duniho | last post by:
This is kind of a question about C# and kind of one about the framework. Hopefully, there's an answer in there somewhere. :) I'm curious about the status of 32-bit vs 64-bit in C# and the framework classes. The specific example I'm running into is with respect to byte arrays and the BitConverter class. In C# you can create arrays larger than 2^32, using the overloaded methods that take 64-bit parameters. But as near as I can tell,...
17
3572
by: Stubert | last post by:
I have a training module db that stores information about employees and what training they have carried our or need to carry out. One table in this database stores what training needs to be carried based on a job title. So if a cleaner joins the company we know that they need the sweeping up training and the mopping up training. I wasn't sure how to store this information but this is what i came up with and as you will see i have hit a...
3
2016
by: John | last post by:
I have two large arrays. Is there a rapid method to comaprs the two arrays and creat a third array of onlt thos items that the are in the first array but not the second array. I do it manually now (compare each item) but it takes forever
3
2567
by: hamishd | last post by:
What is the best way to store large arrays of numbers (eg, 4-byte integers)? Say I want to store an array of 1billion 4-byte integers.. If my computer has 4gB memory, then is this possible? int Large_Array; This will cause a "stack overflow" when i try and execute. How can I do this?
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.