Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78169

Re: Comparison

Newsgroups comp.lang.python
Date 2014-09-22 10:38 -0700
References <521ef86a-df52-4a49-8562-6312273a8c07@googlegroups.com> <mailman.14223.1411405879.18130.python-list@python.org>
Message-ID <0be2cb54-4520-4379-a9bb-279cfe134d19@googlegroups.com> (permalink)
Subject Re: Comparison
From LJ <luisjosenovoa@gmail.com>

Show all headers | View raw


On Monday, September 22, 2014 1:12:23 PM UTC-4, Chris Angelico wrote:
> On Tue, Sep 23, 2014 at 2:57 AM, LJ <luisjosenovoa@gmail.com> wrote:
> 
> > Quick question here. In the code I am working on I am apparently doing a lot of dictionary lookups and those are taking a lot of time.
> 
> > I looked at the possibility of changing the structure and I found about the numpy structured arrays.
> 
> > The concrete question is: what would be the difference between using one or the other in terms of performance? meaning looping and performing checks an operations on them?
> 
> 
> 
> The lookups themselves almost certainly aren't actually taking the
> 
> time, unless you have some kind of crazy hash collision happening,
> 
> which is so statistically unlikely that it would have to have come
> 
> from malice. What's the code doing? What are you trying to accomplish?
> 
> It's much more likely that you have an algorithmic flaw than a data
> 
> type inefficiency.
> 
> 
> 
> ChrisA



Thank you for your reply.

Basically what is happening is the following:

I have a network in which the nodes are defined as dictionaries using the NetworkX package. Inside each node (each dictionary) I defined a dictionary of dictionaries holding attributes corresponding to different ways in which the node can be reached (this dictionaries I refer to as labels). 
At some point in my algorithm I am looping through some subset of nodes and through the labels in each node and I perform some "joining" checks with the labels of each node in another subset of nodes. To clarify I check for a feasibility condition in a pairwise manner for every label in one node and every label of another. This nested loop is taking time.
I wonder if the fact of defining the labels using numpy instead of dictionaries could imply a faster way to perform this loop.

I hope I was clear.

Thanks.

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Comparison LJ <luisjosenovoa@gmail.com> - 2014-09-22 09:57 -0700
  Re: Comparison Chris Angelico <rosuav@gmail.com> - 2014-09-23 03:11 +1000
    Re: Comparison LJ <luisjosenovoa@gmail.com> - 2014-09-22 10:38 -0700
      Re: Comparison Chris Angelico <rosuav@gmail.com> - 2014-09-23 03:45 +1000
      Re: Comparison Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-23 21:13 +1000

csiph-web