Sponsored Content
Top Forums Shell Programming and Scripting Python: make dual vector dot-product more pythonic Post 303041217 by figaro on Monday 18th of November 2019 04:18:23 PM
Old 11-18-2019
Python: make dual vector dot-product more pythonic

I have this dot product, calculating weighted means, and is applied to two columns in a list:
Code:
# calculate weighted values in sequence
for i in range(len(temperatures)-len(weights)):
  temperatures[i].append(sum([weights[j]*temperatures[i+j][5] for j in range(len(weights))]))
  temperatures[i].append(sum([weights[j]*temperatures[i+j][6] for j in range(len(weights))]))

The calculation is a running dot-product, ie the list of temperature samples is far larger than the list of weights, hence the correction of subtracting len(weights) at the end of the main loop.
This traverses the list of weights twice, which is inefficient and degrades performance. How could this be done in a more pythonic way?

I also have concerns about the main loop. Would this be considered more pythonic?:
Code:
# calculate weighted values in sequence
for i in range(len(temperatures)):
   try:
      # weighted calculation here
   except:
      # do nothing, because array out of bounds


Last edited by figaro; 11-18-2019 at 06:01 PM.. Reason: Emphasise the fact that the lists are not of the same length, ie the dot product calculates a running weighted mean.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

make: WARNING- Product is not licensed.

I do beg for my bad english ofr advance (french..) I've a problem with unix sco openserver 5 enterprise system I can't do any make at all! when i do it, i've this message : make: WARNING- Product is not licensed. however, i've entered the license number, code and data information... ... (3 Replies)
Discussion started by: joedelabush
3 Replies

2. UNIX for Dummies Questions & Answers

Backup of Product Database

HI, I know its scarey me asking this, but system is homegrown and I am just having fun, but at the same time dont want to have tooo much fun where the phrase "little knowledge is dangerous" perfectly fits my actions ;-). I have a couple of packages that are failing to be removed... #... (2 Replies)
Discussion started by: Student37
2 Replies

3. HP-UX

TrustedMigration product ?

I'm running HP-UX B.11.23 U ia64 I've got SOX auditors asking me if we have the TrustedMigration product. I don't know what that is and google isn't being helpful. Can you tell me what this product is (and what it is for) and how to know if my system is running it and/or prove that it is... (1 Reply)
Discussion started by: LisaS
1 Replies

4. Shell Programming and Scripting

Make python script ignore .htaccess

I just wrote a tiny script with the help of ghostdog74 to search all my files for special content phrases. After a few modifications I now made it work, but one problem is left. The files are located in public_html folder, so there might also be .htaccess files. So I ignored scanning of that... (4 Replies)
Discussion started by: medic
4 Replies

5. Programming

vector c++

hello guys. i'm new to c++. i've problem using two dimensional vector. i've a project of making conway's game of life. this is the code that i have made so far. my problem is how can i give a two dimensional vector through main. glider.vec1 = vec; is not correct way to give a two... (2 Replies)
Discussion started by: nishrestha
2 Replies

6. Hardware

Fedora 16 dual monitor - dual head - automatic monitor shutdown

Hi, I am experiencing troubles with dual monitors in fedora 16. During boot time both monitors are working, but when system starts one monitor automatically shut down. It happend out of the blue. Some time before when I updated system this happend but then I booted older kernel release and... (0 Replies)
Discussion started by: wakatana
0 Replies

7. UNIX for Beginners Questions & Answers

Which Product to Choose?

Okay, I have an Asus A8NSLI board with an Athlon 64 and I dunno, maybe 8gig Ram and Windows has crashed for the last time so I've finally had enough and I'll make it a Unix machine. I have a new 1Tera drive and I'm all set to go. Which brand of Unix/Linux can you advise me to go for? The... (3 Replies)
Discussion started by: abrogard
3 Replies

8. Shell Programming and Scripting

Pythonic Parsing

Experts and All, Hello ! I am trying to fabricate a simple shell script in python that has taken me almost 5 hours to complete. I am using python 3.6. So, I am trying to read a file, parse the log file and trying to answer this basic question of how many GET's and how many POST's are there... (1 Reply)
Discussion started by: ManoharMa
1 Replies
Grinder::KmerCollection(3pm)				User Contributed Perl Documentation			      Grinder::KmerCollection(3pm)

NAME
Grinder::KmerCollection - A collection of kmers from sequences SYNOPSIS
my $col = Grinder::KmerCollection->new( -k => 10, -file => 'seqs.fa' ); DESCRIPTION
Manage a collection of kmers found in various sequences. Store information about what sequence a kmer was found in and its starting position on the sequence. AUTHOR
Florent Angly <florent.angly@gmail.com> APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Title : new Usage : my $col = Grinder::KmerCollection->new( -k => 10, -file => 'seqs.fa', -revcom => 1 ); Function: Build a new kmer collection Args : -k set the kmer length (default: 10 bp) -revcom count kmers before and after reverse-complementing sequences (default: 0) -seqs count kmers in the provided arrayref of sequences (Bio::Seq objects) -ids if specified, index the sequences provided to -seq using the use the IDs in this arrayref instead of using the sequences $seq->id() method -file count kmers in the provided file of sequences -weights if specified, assign the abundance of each sequence from the values in this arrayref Returns : Grinder::KmerCollection object k Usage : $col->k; Function: Get the length of the kmers Args : None Returns : Positive integer weights Usage : $col->weights({'seq1' => 3, 'seq10' => 0.45}); Function: Get or set the weight of each sequence. Each sequence is given a weight of 1 by default. Args : hashref where the keys are sequence IDs and the values are the weight of the corresponding (e.g. their relative abundance) Returns : Grinder::KmerCollection object collection_by_kmer Usage : $col->collection_by_kmer; Function: Get the collection of kmers, indexed by kmer Args : None Returns : A hashref of hashref of arrayref: hash->{kmer}->{ID of sequences with this kmer}->[starts of kmer on sequence] collection_by_seq Usage : $col->collection_by_seq; Function: Get the collection of kmers, indexed by sequence ID Args : None Returns : A hashref of hashref of arrayref: hash->{ID of sequences with this kmer}->{kmer}->[starts of kmer on sequence] add_file Usage : $col->add_file('seqs.fa'); Function: Process the kmers in the given file of sequences. Args : filename Returns : Grinder::KmerCollection object add_seqs Usage : $col->add_seqs([$seq1, $seq2]); Function: Process the kmers in the given sequences. Args : * arrayref of Bio::Seq objects * arrayref of IDs to use for the indexing of the sequences Returns : Grinder::KmerCollection object filter_rare Usage : $col->filter_rare( 2 ); Function: Remove kmers occurring at less than the (weighted) abundance specified Args : integer Returns : Grinder::KmerCollection object filter_shared Usage : $col->filter_shared( 2 ); Function: Remove kmers occurring in less than the number of sequences specified Args : integer Returns : Grinder::KmerCollection object counts Usage : $col->counts Function: Calculate the total count of each kmer. Counts are affected by the weights you gave to the sequences. Args : * restrict sequences to search to specified sequence ID (optional) * starting position from which counting should start (optional) * 0 to report counts (default), 1 to report frequencies (normalize to 1) Returns : * arrayref of the different kmers * arrayref of the corresponding total counts sources Usage : $col->sources() Function: Return the sources of a kmer and their (weighted) abundance. Args : * kmer to get the sources of * sources to exclude from the results (optional) * 0 to report counts (default), 1 to report frequencies (normalize to 1) Returns : * arrayref of the different sources * arrayref of the corresponding total counts If the kmer requested does not exist, the array will be empty. kmers Usage : $col->kmers('seq1'); Function: This is the inverse of sources(). Return the kmers found in a sequence (given its ID) and their (weighted) abundance. Args : * sequence ID to get the kmers of * 0 to report counts (default), 1 to report frequencies (normalize to 1) Returns : * arrayref of sequence IDs * arrayref of the corresponding total counts If the sequence ID requested does not exist, the arrays will be empty. positions Usage : $col->positions() Function: Return the positions of the given kmer on a given sequence. An error is reported if the kmer requested does not exist Args : * desired kmer * desired sequence with this kmer Returns : Arrayref of the different positions. The arrays will be empty if the desired combination of kmer and sequence was not found. perl v5.14.2 2012-01-17 Grinder::KmerCollection(3pm)
All times are GMT -4. The time now is 02:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy