From 28e005fab8158763e180aea2a9d51a6b165ec2ab 2008-06-04 07:57:03 From: Fernando Perez Date: 2008-06-04 07:57:03 Subject: [PATCH] Add numpy profile and update scipy one to conform to np/sp conventions. --- diff --git a/IPython/Extensions/ipy_profile_numpy.py b/IPython/Extensions/ipy_profile_numpy.py new file mode 100644 index 0000000..a722627 --- /dev/null +++ b/IPython/Extensions/ipy_profile_numpy.py @@ -0,0 +1,24 @@ +""" IPython 'numpy' profile, to preload NumPy. + +This profile loads the math/cmath modules as well as all of numpy. + +It exposes numpy via the 'np' shorthand as well for convenience. +""" + +import IPython.ipapi +import ipy_defaults + +def main(): + ip = IPython.ipapi.get() + + try: + ip.ex("import math,cmath") + ip.ex("import numpy") + ip.ex("import numpy as np") + + ip.ex("from numpy import *") + + except ImportError: + print "Unable to start NumPy profile, is numpy installed?" + +main() diff --git a/IPython/Extensions/ipy_profile_scipy.py b/IPython/Extensions/ipy_profile_scipy.py index 7c929c2..907448a 100644 --- a/IPython/Extensions/ipy_profile_scipy.py +++ b/IPython/Extensions/ipy_profile_scipy.py @@ -1,10 +1,11 @@ -""" IPython 'sci' profile +""" IPython 'scipy' profile, preloads NumPy and SciPy. -Replaces the old scipy profile. +This profile loads the math/cmath modules as well as all of numpy and scipy. +It exposes numpy and scipy via the 'np' and 'sp' shorthands as well for +convenience. """ - import IPython.ipapi import ipy_defaults @@ -12,14 +13,17 @@ def main(): ip = IPython.ipapi.get() try: + ip.ex("import math,cmath") ip.ex("import numpy") ip.ex("import scipy") - + + ip.ex("import numpy as np") + ip.ex("import scipy as sp") + ip.ex("from numpy import *") ip.ex("from scipy import *") - print "SciPy profile successfully loaded." + except ImportError: - print "Unable to start scipy profile, are scipy and numpy installed?" + print "Unable to start scipy profile, are numpy and scipy installed?" - main()