Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning NumPy Array

You're reading from  Learning NumPy Array

Product type Book
Published in Jun 2014
Publisher
ISBN-13 9781783983902
Pages 164 pages
Edition 1st Edition
Languages
Author (1):
Ivan Idris Ivan Idris
Profile icon Ivan Idris

Table of Contents (14) Chapters

Learning NumPy Array
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Getting Started with NumPy NumPy Basics Basic Data Analysis with NumPy Simple Predictive Analytics with NumPy Signal Processing Techniques Profiling, Debugging, and Testing The Scientific Python Ecosystem Index

Analyzing intra-year daily average temperatures


We are going to have a look at the temperature variation within a year by converting dates to the corresponding day of the year in numbers. This number is between 1 and 366, where 1 corresponds to January 1st and 365 (or 366) corresponds to December 31st. Perform the following steps to analyze the intra-year daily average temperature:

  1. Initialize arrays for the range 1-366 with averages initialized to zeros:

    rng = np.arange(1, 366)
    avgs = np.zeros(365)
    avgs2 = np.zeros(365)
  2. Calculate averages by the day of the year before and after a cutoff point:

    for i in rng: 
       indices = np.where(days[:cutoff] == i)
       avgs[i-1] = temp[indices].mean()
       indices = np.where(days[cutoff+1:] == i)
       avgs2[i-1] = temp[indices].mean()
  3. Fit the averages before the cutoff point to a quadratic polynomial (just a first-order approximation):

    poly = np.polyfit(rng, avgs, 2)
    print poly

    The following polynomial coefficients in descending power are printed:

    [ -4.91329859e-04...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}