Python Forum
How to efficiently average same entries of lists in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to efficiently average same entries of lists in a list
#1
Hello,

I am working on data from which I calculate (using peakutilis) 4 peaks.
These positions of the 4 peaks are stored in a list like:
[3141, 4989, 5499, 6714]

I have over a hundred nearly similar data sets, and I want to efficiently calculate the average of each entry position (entry in the list)

For now I am doing it like this:

indexlist = []
for t, scope_y in enumerate(scope_ys):
    scope_y = scope_y[0]
    indexes = peakutils.indexes(scope_y, thres=0.07, min_dist=500)
    indexlist.append(indexes)

v = np.asarray(indexlist)
a_lst = []
b_lst = []
c_lst = []
d_lst = []

for i in range(len(v)):
    a = v[i,0]
    a_lst.append(a)
    b = v[i,1]
    b_lst.append(b)
    c = v[i,2]
    c_lst.append(c)
    d = v[i,3]
    d_lst.append(d)
for i in range(4):
    a_avg = int(np.average(a_lst))
    b_avg = int(np.average(b_lst))
    c_avg = int(np.average(c_lst))
    d_avg = int(np.average(d_lst))
indexes = [a_avg,b_avg,c_avg,d_avg]
print(indexes) 
Do you know how to do this in a more efficient way?

Regards,
xquad

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
How to efficiently average same entries of lists in a list - by xquad - Dec-17-2021, 03:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List all possibilities of a nested-list by flattened lists sparkt 1 945 Feb-23-2023, 02:21 PM
Last Post: sparkt
  How to read in mulitple files efficiently garynewport 3 907 Jan-27-2023, 10:44 AM
Last Post: DeaD_EyE
  user input values into list of lists tauros73 3 1,095 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  returning a List of Lists nafshar 3 1,111 Oct-28-2022, 06:28 PM
Last Post: deanhystad
  Creating list of lists, with objects from lists sgrinderud 7 1,712 Oct-01-2022, 07:15 PM
Last Post: Skaperen
  How to get unique entries in a list and the count of occurrence james2009 5 3,020 May-08-2022, 04:34 AM
Last Post: ndc85430
  sorting a list of lists by an element leapcfm 3 1,920 Sep-10-2021, 03:33 PM
Last Post: leapcfm
  behavior list of lists roym 5 2,143 Jul-04-2021, 04:43 PM
Last Post: roym
  List of lists - merge sublists with common elements medatib531 1 3,423 May-09-2021, 07:49 AM
Last Post: Gribouillis
  Sort List of Lists by Column Nju 1 11,978 Apr-13-2021, 11:59 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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