Python Forum
Counting Number of Element in a smart way
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Counting Number of Element in a smart way
#2
If the only objection is writing out the triplets, you could do the following. It runs the same commands, just does it in a loop.

from itertool import product
triplets = tuple(product((0, 1), repeat = 3))
sums = {}
for triple in triplets:
    sums[triple] = sum(np.all((results-np.array(triple))==0, axis=1))
The sums will be in a dict sums rather than as separate variables. But you can pull them out, or you could change how the keys are named.

However, this doesn't change the fundamental calls made. Perhaps someone else can see if there's a better way to have numpy do the sum more directly.
quest likes this post
Reply


Messages In This Thread
RE: Counting Number of Element in a smart way - by bowlofred - Nov-09-2020, 09:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [split] How to ask Smart Questions (thread title expansion) darkuser 4 1,715 Nov-11-2024, 01:27 PM
Last Post: deanhystad
  Counting number of words and organize for the bigger frequencies to the small ones. valeriorsneto 1 2,386 Feb-05-2021, 03:49 PM
Last Post: perfringo
  Counting Element in Multidimensional List quest_ 1 2,978 Nov-25-2020, 10:00 PM
Last Post: quest_
  get method not counting number of strings in dictionary LearningTocode 2 2,974 Jun-13-2020, 11:17 PM
Last Post: LearningTocode
  counting items in a list of number combinations Dixon 2 2,813 Feb-19-2020, 07:06 PM
Last Post: Dixon
  Counting number of occurrences of a single digit in a list python_newbie09 12 9,001 Aug-12-2019, 01:31 PM
Last Post: perfringo
  How to list number of times element is in defaultdict and delete it mrapple2020 3 3,614 Apr-15-2019, 07:34 AM
Last Post: perfringo
  Build class to make a Smart list - trying icm63 7 4,976 Mar-28-2019, 08:53 PM
Last Post: icm63
  Adding a line number to an lxml Element vindy 0 4,602 Mar-08-2019, 08:34 PM
Last Post: vindy
  Counting the number of letters in a string alphabetically TreasureDragon 2 4,023 Mar-07-2019, 01:03 AM
Last Post: TreasureDragon

Forum Jump:

User Panel Messages

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