Tuesday, December 31, 2019

Python SciPy Basic program

Python SciPy Basic program 

SciPy is an Open Source Python-based library, which is used in mathematics, scientific computing, Engineering, and technical computing.

To install SciPy, below was the instruction

sudo port install py35-scipy py35-numpy

(PyLearning) mymachine-M-91RJ:PyLearning mymachine$ Python3 -m pip install --user numpy scipy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/ea/f4/acaa005b20777fc56a1dc0cae228ab2cb5a7f09a7e7fcb6d4619ce24a1b7/numpy-1.17.3-cp37-cp37m-macosx_10_9_x86_64.whl (15.1MB)
    100% |████████████████████████████████| 15.1MB 2.1MB/s
Collecting scipy
  Downloading https://files.pythonhosted.org/packages/d5/06/1a696649f4b2e706c509cb9333fdc6331fbe71251cede945f9e1fa13ea34/scipy-1.3.1-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (27.7MB)
    100% |████████████████████████████████| 27.7MB 1.1MB/s
Installing collected packages: numpy, scipy
  The scripts f2py, f2py3 and f2py3.7 are installed in '/Users/mymachine/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

It was giving this error. As a result, executing the below steps was able to resolve this error and

#run these using python3 instead of python.
#to install scipy and numpy for python3, follow the below steps
#pip3 install numpy
#pip3 install scipy

import numpy as np
from scipy import io as sio
array = np.ones((4, 4))
sio.savemat('example.mat', {'ar': array})
data = sio.loadmat('example.mat', struct_as_record=True)
print(data['ar'])


References:
https://www.guru99.com/scipy-tutorial.html

No comments:

Post a Comment