Skip to content

How to avoid using for loop in these kind of situations #1500

Discussion options

You must be logged in to vote

Well, first thing: the uproot.TBranch.array method reads data and you don't want to read and re-read the same data over and over. You could pass a cache to the array method so that it would check the cache for an already-read value instead of getting it from the file, but it's probably easier to just move the

signal_xgb = event_signal_xgb['DiphotonMVA_self'].array(library = 'np')
bkg_pp_xgb = event_bkg_pp_xgb['DiphotonMVA_self'].array(library = 'np')
bkg_pfff_xgb = event_bkg_pfff_xgb['DiphotonMVA_self'].array(library = 'np')

read commands out of the loop and just use those arrays, rather than reading them, in the loop.

Secondly, you can remove the sums that don't depend on i outside the l…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@ZhenxuanZhang-Jensen
Comment options

@agoose77
Comment options

@ZhenxuanZhang-Jensen
Comment options

@jpivarski
Comment options

@ZhenxuanZhang-Jensen
Comment options

Answer selected by ZhenxuanZhang-Jensen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants