Book Image

SciPy Recipes

By : V Kishore Ayyadevara, Ruben Oliva Ramos
Book Image

SciPy Recipes

By: V Kishore Ayyadevara, Ruben Oliva Ramos

Overview of this book

With the SciPy Stack, you get the power to effectively process, manipulate, and visualize your data using the popular Python language. Utilizing SciPy correctly can sometimes be a very tricky proposition. This book provides the right techniques so you can use SciPy to perform different data science tasks with ease. This book includes hands-on recipes for using the different components of the SciPy Stack such as NumPy, SciPy, matplotlib, and pandas, among others. You will use these libraries to solve real-world problems in linear algebra, numerical analysis, data visualization, and much more. The recipes included in the book will ensure you get a practical understanding not only of how a particular feature in SciPy Stack works, but also of its application to real-world problems. The independent nature of the recipes also ensure that you can pick up any one and learn about a particular feature of SciPy without reading through the other recipes, thus making the book a very handy and useful guide.
Table of Contents (11 chapters)

Using conda environments to run different versions of Python

Another situation that comes up often is the need to test a package in a different version of Python. conda makes it easy to create a suitable environment. In this recipe, we will show you how to create and use environments with version 2.7 of Python.

Getting ready

This recipe assumes that you have a working installation of Anaconda. If you don't, follow the recipe for installing Anaconda on your operating system presented previously in this chapter.

How to do it...

  1. Create the new environment with the following command:
conda create --name python27 python=2.7

conda will display information about the changes and ask for confirmation. Go ahead and enter yes to accept the environment creation.

  1. To activate the environment on Linux and macOS, use the following command:
source activate python27
  1. On Windows, the command to activate an environment is as follows:
activate python27
  1. Let's now test the new environment. Start Python in the usual way after activating the environment. Notice that in the startup message, it should state that version 2.7 of Python is being run. Now run the following statement in the Python prompt:
zip([['a','b'],[1,2]])
  1. This will produce the following output:
[('a', 1), ('b', 2)]
  1. This confirms that we are running Python 2, since in Python 3 the zip() function returns an iterator object instead of a list. To leave the Python shell, run the following in the Python prompt:
quit()
  1. When done with the environment, deactivate it by running the following command on Linux and macOS:
source deactivate python27
  1. On Windows, run the following:
deactivate python27