Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numpy array
#11
Thanks Serafim!! And yes the error has to do with the short example of the file. I'm gonna try what you posted in the timings. I usually run for 100 iterations, and do that 10 times. I'll post back here after I get results.

Brian
Reply
#12
Well I did some timing of your code. It did give correct results!! The only thing was, I had to stop it after the first 5 results were printed. It took extremely long just to get 5 results (over a minute). In the code that I wrote it took .0156 seconds to produce 100 results. I tried it, sorry about the results.
Reply
#13
Well, sometimes beautiful is not the thing. Optimizing for speed often gives much larger code. But it looks nicer! I believe that it is the "any" construction that screws up the timing, not the combination stuff.
Reply
#14
I gave it some more thought and in fact it is unnecessary to do the "any" calculation. It is sufficient with (line 10 below instead of line 32 in the previous program):
while line_no <= draws_reporting:
    b = layer_start
    two_counter = 0
    draw_two = list(combinations(d5[a], 2))
    two_counter = 0
    for two in d5:
        two_1 = list(combinations(d5[b], 2))
        found = False
        for draw in draw_two:
            if draw in two_1:
                found = True
                break
        if not found:
            b += 1
            two_counter += 1
    print(two_counter)
    line_no += 1
    a += 1
    layer_start += 1
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  reshaping 2D numpy array paul18fr 3 959 Jan-03-2023, 06:45 PM
Last Post: paul18fr
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,499 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  How to fill datetime64 field in numpy structured array? AlekseyPython 0 2,209 Oct-20-2020, 08:17 AM
Last Post: AlekseyPython
  Adding data in 3D array from 2D numpy array asmasattar 0 2,157 Jul-23-2020, 10:55 AM
Last Post: asmasattar
  converting dataframe to int numpy array glennford49 1 2,269 Apr-04-2020, 06:15 AM
Last Post: snippsat
  Replacing sub array in Numpy array ThemePark 5 4,037 Apr-01-2020, 01:16 PM
Last Post: ThemePark
  How to prepare a NumPy array which include float type array elements subhash 0 1,873 Mar-02-2020, 06:46 AM
Last Post: subhash
  numpy.where array search for string in just one coordinate adetheheat 1 2,228 Jan-09-2020, 07:09 PM
Last Post: paul18fr
  memory issue loading movie to numpy array djf123 1 2,229 Nov-07-2019, 06:19 AM
Last Post: ThomasL
  Numpy structured array Nitram 3 2,772 Sep-17-2019, 10:09 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020