What is the fastest way to code this particular block of code below..
I used numeric for this currently and I thought it should be really
fast..
But, for large sets of data (bx and vbox) it takes a long time and I
would like to improve.
vbox = array(m) (size: 1000x1000 approx)
for b in bx:
vbox[ b[1], b[0]:b[2] ] = 0
vbox[ b[3], b[0]:b[2] ] = 0
vbox[ b[1]:b[3], b[0] ] = 0
vbox[ b[1]:b[3], b[2] ] = 0
and vbox is a 2D array
where bx is of form [( int,int,int,int),(........) ] 3 1492 qu*****@gmail.com wrote: vbox = array(m) (size: 1000x1000 approx) for b in bx: vbox[ b[1], b[0]:b[2] ] = 0 vbox[ b[3], b[0]:b[2] ] = 0 vbox[ b[1]:b[3], b[0] ] = 0 vbox[ b[1]:b[3], b[2] ] = 0
This may not help, but you could try to minimize the number of times you
call b's __getitem__, e.g.:
for b0, b1, b2, b3 in bx:
vbox[b1, b0:b2] = 0
vbox[b3, b0:b2] = 0
vbox[b1:b3, b0] = 0
vbox[b1:b3, b2] = 0
If it helps, I wouldn't expect it to help a lot though. You could also try:
for b0, b1, b2, b3 in bx:
b0_2 = slice(b0, b2)
b1_3 = slice(b1, b3)
vbox[b1, b0_2] = 0
vbox[b3, b0_2] = 0
vbox[b1_3, b0] = 0
vbox[b1_3, b2] = 0
But again, I wouldn't expect dramatic improvements...
STeVe qu*****@gmail.com wrote: What is the fastest way to code this particular block of code below.. I used numeric for this currently and I thought it should be really fast.. But, for large sets of data (bx and vbox) it takes a long time and I would like to improve.
vbox = array(m) (size: 1000x1000 approx) for b in bx: vbox[ b[1], b[0]:b[2] ] = 0 vbox[ b[3], b[0]:b[2] ] = 0 vbox[ b[1]:b[3], b[0] ] = 0 vbox[ b[1]:b[3], b[2] ] = 0
and vbox is a 2D array where bx is of form [( int,int,int,int),(........) ]
You can try
for b0, b1, b2, b3 in bx:
vbox[b1:b3, b0:b2+1:b2-b0] = 0
vbox[b1:b3+1:b3-b1, b0:b2] = 0
By the way, the bottom/right cell of your box remains nonzero. Is that
intentional?
Peter
Actually slicing the way you suggested improved it to some extent. I
did profile on this and I observed that it reduced the number of calls
for __get_item__ and improved the timing to some extent. Which was
useful to some extent.
Thanks again. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brian Patterson |
last post by:
I have noticed in the book of words that hasattr works by calling getattr
and raising an exception if no such attribute exists. If I need the value
in any case, am I better off using getattr...
|
by: Roy Smith |
last post by:
I've been running some benchmarks to compare streams and stdio
performance. I've always suspected stdio was faster, but was
astonished to discover how much faster. I timed the following running...
|
by: pembed2003 |
last post by:
Hi all,
I asked this question in the C group but no one seems to be interested
in answering it. :-( Basically, I wrote a search and replace function
so I can do:
char source = "abcd?1234?x";...
|
by: Sean Kenwrick |
last post by:
I am writing a byte-code interpreter/emulator for a language that
exclusively uses strings for variables (i.e all variables are pushed onto
the stack as strings). Therefore for arithmetic...
|
by: Peng Jian |
last post by:
I have a function that is called very very often.
Can I improve its efficiency by declaring its local variables to be static?
| |
by: philipl |
last post by:
hi,
I have some code here which basically look for within a string, the
occurance of any 3 consectative characters which are the same. so AAA
bbb etc would be reported by this function. I later...
|
by: sdanda |
last post by:
Hi ,
Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity .........
This has to work for more than 8,00,000...
|
by: oravm |
last post by:
Hi,
I re-write a query and used bulk collect to improve the performance of the batch process. The query below has NO compile error but when execute query there is error 'ORA-01403: no data...
|
by: Gilles Ganault |
last post by:
Hello
I'm no PHP expert, and I'm reading "Building scalable web sites". In
the tips section, the author mentions using templates to speed things
up. I was wondering how the template engines...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |