Ticket #7197: trac_7197_part4.patch

File trac_7197_part4.patch, 2.9 KB (added by amhou, 12 years ago)
  • sage/all.py

    # HG changeset patch
    # User Andrew Hou <amhou@uw.edu>
    # Date 1257640893 28800
    # Node ID bbf5f88f04e9bd4aefd7d16e09b72b2328d6ce96
    # Parent  90a5eeacff8d573ab6cf5c90639ce95946f9a41f
    copyright header block added
    numpy imported in functions where they're used
    
    diff -r 90a5eeacff8d -r bbf5f88f04e9 sage/all.py
    a b  
    134134from sage.numerical.all  import *
    135135
    136136from sage.stats.all      import *
     137import sage.stats.all as stats
    137138
    138139import sage.finance.all  as finance
    139140
  • sage/stats/all.py

    diff -r 90a5eeacff8d -r bbf5f88f04e9 sage/stats/all.py
    a b  
    11from r import (ttest)
    2 from basic_stats import *
     2from basic_stats import (mean, mode, std, variance, median)
    33
    44import hmm.all as hmm
    55
  • sage/stats/basic_stats.py

    diff -r 90a5eeacff8d -r bbf5f88f04e9 sage/stats/basic_stats.py
    a b  
     1"""
     2Basic Statistics
     3
     4This file contains basic descriptive functions.
     5
     6AUTHOR:
     7    - Andrew Hou (11/06/2009)
     8 
     9"""
     10######################################################################
     11#       Copyright (C) 2009, Andrew Hou <amhou@uw.edu>
     12#
     13#  Distributed under the terms of the GNU General Public License (GPL)
     14#
     15#  The full text of the GPL is available at:
     16#                  http://www.gnu.org/licenses/
     17####################################################################
     18
    119from sage.rings.integer_ring import ZZ
    220from sage.symbolic.constants import NaN
    3 from operator import itemgetter
    421from sage.functions.other import sqrt
    5 import numpy
    622
    723def mean(v):
    824    """
     
    7288        sage: mode(['sage', 4, I, 3/5, 'sage', pi])
    7389        [('sage', 2)]
    7490    """
     91    from operator import itemgetter
     92
    7593    freq = {}
    7694    if hasattr(v, 'mode'): return v.mode()
    7795    for i in v:
     
    123141        sqrt(1/450*(5*sqrt(2) + 5*I - 6)^2 + 1/450*(5*sqrt(2) - 10*I + 3)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2)
    124142        sage: std([RIF(1.0103, 1.0103), RIF(2)])
    125143        0.6998235813403261?
    126 
     144        sage: import numpy
     145        sage: x = numpy.array([1,2,3,4,5])
     146        sage: std(x, bias=False)
     147        1.5811388300841898
    127148
    128149    """
     150    import numpy
     151
    129152    x = 0
    130153    if type(v) is numpy.ndarray:
    131154        # accounts for numpy arrays
     
    189212        1/450*(5*sqrt(2) + 5*I - 6)^2 + 1/450*(5*sqrt(2) - 10*I + 3)^2 + 1/450*(10*sqrt(2) - 5*I - 3)^2
    190213        sage: variance([RIF(1.0103, 1.0103), RIF(2)])
    191214        0.4897530450000000?
     215        sage: import numpy
     216        sage: x = numpy.array([1,2,3,4,5])
     217        sage: variance(x, bias=False)
     218        2.5
    192219
    193220
    194221    """
     222    import numpy
     223
    195224    x = 0
    196225    if type(v) == numpy.ndarray:
    197226        # accounts for numpy arrays
     
    257286        upper = values[len(values)/2]
    258287        return (lower + upper)/ZZ(2)
    259288
     289