<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: counting search cursor results in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624641#M20682</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That method does work, but it isn't any faster (at least with my tables) than using a search cursor and iterating through it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Sep 2010 17:48:48 GMT</pubDate>
    <dc:creator>MikeTischler</dc:creator>
    <dc:date>2010-09-03T17:48:48Z</dc:date>
    <item>
      <title>counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624637#M20678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using the arcpy.SearchCursor code to query a standalone table.&amp;nbsp; All I really need is the count of the results - not any of the actual data.&amp;nbsp; The searchcursor itself finishes rather quickly, but iterating through the search cursor takes a surprisingly long time.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the method I'm using.&amp;nbsp; Is there a faster way to get what I need?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; rows = arcpy.SearchCursor(table,searchstring)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #count the number of rows in output&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Sep 2010 12:24:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624637#M20678</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2010-09-03T12:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624638#M20679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;For sure, "Get Count":&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000n7000000.htm"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//0017000000n7000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need a selection/search on it, you can do a "make table view" then "select by attribute" Adding these couple steps might slow it down a little, however if you just want the number of rows in a table, featureclass, etc - Get Count should be the fastest.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Sep 2010 14:39:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624638#M20679</guid>
      <dc:creator>KevinHibma</dc:creator>
      <dc:date>2010-09-03T14:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624639#M20680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried making a table view and then running GetCount on that, and it didn't seem any faster than what I was doing before.&amp;nbsp; And unfortunately, I can't run GetCount on the SearchCursor object.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Sep 2010 14:59:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624639#M20680</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2010-09-03T14:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624640#M20681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just use the SQL paramater of either the MakeFeatureLayer or MakeTableView tool, then the GetCount tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It should take like 1 second. Some v9.3 code for example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;gp.MakeFeatureLayer_management(indxTileFC, indxTileFL, "FID_local_know_nw &amp;gt; -1")
if int(gp.GetCount_management(indxTileFL).getoutput(0)) &amp;gt; 0:
&amp;nbsp;&amp;nbsp; gp.Blah_managment(this, that, theOther)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:36:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624640#M20681</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T02:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624641#M20682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That method does work, but it isn't any faster (at least with my tables) than using a search cursor and iterating through it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Sep 2010 17:48:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624641#M20682</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2010-09-03T17:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624642#M20683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How many rows are in your table?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Sep 2010 02:23:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624642#M20683</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-09-08T02:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624643#M20684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is a mystery -- Get Count (using the mechanics that Chris showed) should be WAY faster than cycling through the records with a cursor.&amp;nbsp; There's something about your data or process that we're missing -- any other clues (besides # of records, like Chris asks?)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Sep 2010 03:41:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624643#M20684</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2010-09-08T03:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624644#M20685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry for the late response - my email filter sent the reply notices to my spam folder.&amp;nbsp; Go figure.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are a substantial amount of records for some tables....3-4 million in a few cases.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A test with a 2,130,000 records took 19.07 seconds using the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from arcpy import *
from stopwatch import clockit
@clockit
def maketv_count(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management(table,"mytv5k","NEAR_DIST &amp;lt; 1000")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetCount_management("mytv5k")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;using a search cursor and iterating through took 19.43 seconds using this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def maketv_cursor(table):
 
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(table,"NEAR_DIST &amp;lt; 1000")
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Granted, 2 million records is a LOT...but I didn't expect the methods to be nearly identical in their speed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:36:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624644#M20685</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2021-12-12T02:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624645#M20686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well.... That's a lot of records - seems 20 seconds would be a reasoable time to expect to return the number of selected records in 2.1 million record table! However:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. If you add an attribute index, the performance &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;may&lt;/SPAN&gt;&lt;SPAN&gt; increase (probably for both the cursor and getcount methods): &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000005z000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000005z000000.htm&lt;/A&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s00000011000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005s00000011000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. This probably isn't any faster (could be for some weird reason though?), but there is a nifty geoprocessing scripting function that will return the OIDs of a selected set of records within a feature layer. From that you can gleen the selected count. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;gp.MakeFeatureLayer_management(fc, "fl")
gp.SelectLayerByAttribute_management("fl", "NEW_SELECTION", "WIDGETS &amp;gt; 30")
fidSet = gp.describe("fl").fidset #this returns a big honking text string - can be millions of charatcters long in my experience!
selectedOidList = []
for fid in fidSet.split(";"):
&amp;nbsp;&amp;nbsp; selectedOidList.append(fid)
print len(selectedOidList)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:36:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624645#M20686</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T02:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624646#M20687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also, I should mention that if you have to find the selected record count repeated (like in some sort of loop), I would suggest investigating a Python dictionary object. Basically you have to take an initial time hit by loading the table's records into the dictionary, but once it's there.... Holy crap it's fast (light speed and not magnetic speed)!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/8428-Setting-a-Single-Record-to-Selected-with-Python?p=25930&amp;amp;viewfull=1#post25930"&gt;http://forums.arcgis.com/threads/8428-Setting-a-Single-Record-to-Selected-with-Python?p=25930&amp;amp;viewfull=1#post25930&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Sep 2010 21:24:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624646#M20687</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-09-09T21:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624647#M20688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Surely you don't need to iterate the split list?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is already a list after a split&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print len(fidSet.split(";"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;just being economical.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Sep 2010 13:04:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624647#M20688</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2010-09-10T13:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624648#M20689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the tips.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Re: suggestion 1, I don't think I can use SelectLayerByAttribute because I have a standalone table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Re: suggestion 2, I thought this might be the winner, since I do have a series of searches to run over the same table.&amp;nbsp; However, the overhead in creating the 2.3mil key:value pairs was REALLY expensive.&amp;nbsp; I let my script run for about 6-7 minutes, and the dictionary hadn't yet been created...let alone complete any searches.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought I might be able to leverage some functionality from numpy, since all my values are numeric.&amp;nbsp; Turns out there is a pretty cool way to load an array (my_array = numpy.fromiter) but that, too, was quite expensive.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For comparison sake, I used a smaller table with ~160K records.&amp;nbsp; For each of the trials, I started a fresh ArcMap session.&amp;nbsp; I'm not sure if the individual methods are coded the best, but here's the times and code to run 10 searches over the same table:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;by cursor:14.17s&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;by making table and counting: 28.4s&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;by dictionary: 98.5s&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from arcpy import *
from stopwatch import clockit
from numpy import *

@clockit
def do_search_by_count(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(100,1000,100):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; searchstring = "NEAR_DIST &amp;lt; " + str(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += make_table_and_count(table, searchstring)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "done by count: " + str(count)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return count

@clockit
def do_search_by_cursor(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(100,1000,100):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; searchstring = "NEAR_DIST &amp;lt; " + str(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += cursor_search_count(table,searchstring)&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "done by cursor: " + str(count)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return count

@clockit
def do_search_by_dict(table):

&amp;nbsp;&amp;nbsp;&amp;nbsp; lookupDict = create_dict(table)&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(100,1000,100):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += count_dict(lookupDict,i)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "done with dict: " + str(count)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return count

@clockit
def make_table_and_count(table,searchstring):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeTableView_management(table,"mytv5k",searchstring)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = int(str(arcpy.GetCount_management("mytv5k")))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
@clockit
def cursor_search_count(table,searchstring):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(table,searchstring)
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; return count
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
@clockit
def create_dict(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lookupDict = {}
&amp;nbsp;&amp;nbsp;&amp;nbsp; searchRows = arcpy.SearchCursor(table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for myrow in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lookupDict[myrow.OBJECTID] = [myrow.NEAR_DIST]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; del myrow
&amp;nbsp;&amp;nbsp;&amp;nbsp; del searchRows
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "created dict"
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lookupDict

@clockit
def count_dict(lookupDict,dist):
&amp;nbsp;&amp;nbsp;&amp;nbsp; count =0
&amp;nbsp;&amp;nbsp;&amp;nbsp; for k,v in lookupDict.iteritems():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if v[0] &amp;lt; dist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; return count
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for the tips.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:36:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624648#M20689</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2021-12-12T02:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624649#M20690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It is already a list after a split&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, typing faster than I was thinking...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Sep 2010 14:50:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624649#M20690</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-09-10T14:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624650#M20691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;And if anyone's interested, the numpy-based method clocked in at 62.6s&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;@clockit
def do_search_by_numpy(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; my_array = numpy.fromiter(countrows(table),dtype=numpy.dtype(float))
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(100,1000,100):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count += numpy.size(where(my_array &amp;lt; i))
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "done with dict: " + str(count)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return count

@clockit
def countrows(table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; searchRows = arcpy.SearchCursor(table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for myrow in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield myrow.NEAR_DIST&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:36:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624650#M20691</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2021-12-12T02:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624651#M20692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;suggestion 1, I don't think I can use SelectLayerByAttribute because I have a standalone table&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In fact you can use a table with SelectLayerByAttribute, but use the MakeTableView tool 1st (in lieu of MakeFeatureLayer), and use the tableview as input.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Re: suggestion 2, I thought this might be the winner, since I do have a series of searches to run over the same table.&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The dictionary idea is probably only a good idea if you have to search the table a whole lot (like hundreds of times - as noted in another thread, it can be a good replacement for an embedded cursor, or some sort of tracing algorithm), because you right, there is a lot of overhead, but maybe something basic like this would work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#v9.3 code BTW
dict = {}
searchRows = gp.searchcursor(tblPath)
searchRow = searchRows.next()
while searchRow:
&amp;nbsp;&amp;nbsp; dict[searchRow.MY_KEY] = [searchRow.FIELD1,searchRow.FIELD2] #this could be a tuple instead of a list to save memory if you didn't plan on changing the values... 
&amp;nbsp;&amp;nbsp; searchRow = searchRows.next()
del searchRow
del searchRows

#yes, there's probably a faster/more elegant way to do this... Kim? .iteritems or .itervalues any faster?
rowCounter1 = 0
rowCounter2 = 0
for myKey in dict:
&amp;nbsp;&amp;nbsp; if dict[myKey][0] == 100 or dict[myKey][1] == "dog":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rowCounter1 = rowCounter1 + 1
&amp;nbsp;&amp;nbsp; if dict[myKey][0] == 200 or dict[myKey][1] == "cat":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rowCounter2 = rowCounter2 + 1&amp;nbsp;&amp;nbsp; 
print rowCounter1
print rowCounter2&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:36:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624651#M20692</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T02:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624652#M20693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just playing around with it, but this code (1.5 million keys) took less than 1 second to execute on my machine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dict = {}
for item in range(1,1500000):
&amp;nbsp;&amp;nbsp; dict[item] = random.uniform(1,10) #return a random float
count = 0
for item in dict:
&amp;nbsp;&amp;nbsp; if dict[item] &amp;gt; 5:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + 1
print count

&amp;gt;&amp;gt;&amp;gt; 833384&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:36:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624652#M20693</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T02:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624653#M20694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;huh&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried your code in the last reply in the python window inside arcmap, and it took 46s and change.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From a pythonwin command line, it took just over 1s.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;hmmm...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Sep 2010 16:22:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624653#M20694</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2010-09-10T16:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624654#M20695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hmm indeed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm pretty much PythonWin all the way... That new-fangled PythonWindow is strange and scary to me. I still can't figure out how to execute simple Spatial Analyst commands though the blasted thing - the help seems totally contradictory! Good ole' SingleOutpuMapAlgebra tool.... look what they have done to you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Sep 2010 16:34:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624654#M20695</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-09-10T16:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624655#M20696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wow - so running the same scripts in a pythonwin window yielded the following results.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;search by making table and getcount: 4.3s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;search by iterating cursor: 6.5s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;search by dictionary: 16.18&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;search by numpy: 12.54&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;obviously, I need to get out of the python window in ArcGIS 10.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Sep 2010 16:38:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624655#M20696</guid>
      <dc:creator>MikeTischler</dc:creator>
      <dc:date>2010-09-10T16:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: counting search cursor results</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624656#M20697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;obviously, I need to get out of the python window in ArcGIS 10&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ESRI/Anyone know why there is a performance issue here? I thought that gp-type code (like cursors, ESRI tools, etc.) was supposed to run faster in the Toolbox and PythonWindow environments compared to extrenal IDEs like PythonWin and Wing... What happened to that "in process" thing?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Sep 2010 16:45:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/counting-search-cursor-results/m-p/624656#M20697</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-09-10T16:45:09Z</dc:date>
    </item>
  </channel>
</rss>

