Python Forum
Sum only some values from a two-dimensional list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sum only some values from a two-dimensional list
#1
Hello,
I'm a newbie. I have a two-dimensional list like this
DATA = 0
# quality control flag
QC = 1
samples = [[0.1, 33.3, 4.4], [1, 0, 2]]
where 3 samples and their 3 quality flags are collected. To calculate the average of all the data, I usually do:
mean = sum (map (float, samples[DATA])) / float (len (samples[DATA]))
But now I want to calculate the average using only the data that have flag > 0

I appreciate any help.
Reply


Messages In This Thread
Sum only some values from a two-dimensional list - by bronfai - Feb-11-2018, 04:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copying the order of another list with identical values gohanhango 7 1,194 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,290 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Comparing List values to get indexes Edward_ 7 1,220 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Adding values with reduce() function from the list of tuples kinimod 10 2,743 Jan-24-2023, 08:22 AM
Last Post: perfringo
  user input values into list of lists tauros73 3 1,094 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  How to quantize a 4 dimensional array? PythonNPC 2 1,655 Apr-23-2022, 04:34 PM
Last Post: Gribouillis
  How to create 2 dimensional variables in Python? plumberpy 5 1,903 Mar-31-2022, 03:15 AM
Last Post: plumberpy
  AttributeError: 'list' object has no attribute 'values' ilknurg 4 15,102 Jan-19-2022, 08:33 AM
Last Post: menator01
  Slicing a 2 dimensional array Scott 2 1,680 Jan-12-2022, 07:18 AM
Last Post: paul18fr
  Need to parse a list of boolean columns inside a list and return true values Python84 4 2,144 Jan-09-2022, 02:39 AM
Last Post: Python84

Forum Jump:

User Panel Messages

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