Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numpy Help
#1
Hey everyone,

This is my first time posting on this forum. I am very very new to python, so please bare with me. I'll try and give as much accurate information as possible.

First off I'm using Ubuntu 16. I have Anaconda 5.0 installed, with the python3 package. What I'm attempting to do is learn python while working on a real world project at the same time, since I think it will keep me motivated. My goal/project is to understand and create a working artificial neural network for solving non linear problems.

I have some code, that I found on the internet. It's what I'm working from to try and understand how an ANN works.

Code:
import numpy as np

# sigmoid function
def nonlin(x,deriv=False):
    if(deriv==True):
        return x*(1-x)
    return 1/(1+np.exp(-x))
    
# input dataset
X = np.array([  [0,0,1],
                [0,1,1],
                [1,0,1],
                [1,1,1] ])
    
# output dataset            
y = np.array([[0,0,1,1]]).T

# seed random numbers to make calculation
# deterministic (just a good practice)
np.random.seed(1)

# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3,1)) - 1

for iter in xrange(10000):

    # forward propagation
    l0 = X
    l1 = nonlin(np.dot(l0,syn0))

    # how much did we miss?
    l1_error = y - l1

    # multiply how much we missed by the 
    # slope of the sigmoid at the values in l1
    l1_delta = l1_error * nonlin(l1,True)

    # update weights
    syn0 += np.dot(l0.T,l1_delta)

print ("Output After Training:")
print (l1)
I currently have an Anaconda environment set up using python2.7 to handle this code in Spyder. This is because I think that's what the author of this code was using. I'm trying to run this code to see if it works, and to see if my work space is set up to handle a ANN. When I run it this is the error I keep getting, and I don't understand how to fix it.

Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19)
Type "copyright", "credits" or "license" for more information.

IPython 5.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: debugfile('/home/b/.config/spyder/temp.py', wdir='/home/b/.config/spyder')
> /home/b/.config/spyder/temp.py(1)<module>()
----> 1 import numpy as np
      2 
      3 # sigmoid function
      4 def nonlin(x,deriv=False):
      5     if(deriv==True):
Is this happening because Spyder doesn't have the right modules loaded up (numpy)?

Thanks guys Huh
Reply
#2
Quote:I currently have an Anaconda environment set up using python2.7 to handle this code in Spyder. This is because I think that's what the author of this code was using. I'm trying to run this code to see if it works, and to see if my work space is set up to handle a ANN. When I run it this is the error I keep getting, and I don't understand how to fix it.
Your just trying to run the above code?

I dont use Anaconda, so i cant really help with that issue. But to run the first snippet all you would need is python2.x and numpy for that same version. I say 2.x because the code has xrange()

If your on linux....you can just do pip install numpy
and then run the code in python2.x from the terminal

If you want to run it under python3.x then remove the x from xrange() and pip3 install numpy and then run the same code with the python3.x interpreter
Recommended Tutorials:
Reply
#3
packages are loaded for particular versions of python, this is where the problem may lie.
I'm not familiar with Anaconda. Is there a way to list installed packages in one of their tools?
I use:
import pip
pip.get_installed_distributions()
on windows, but not sure if you can use the same on Linux.
Reply
#4
Quote:Is there a way to list installed packages in one of their tools?
it appears you would have to do
conda list
based on this below. But i was under the impression that anaconda lready came iwth numpy, that is where it shines, pre-installed packages.
https://conda.io/docs/_downloads/conda-cheatsheet.pdf

Quote:but not sure if you can use the same on Linux.
yes it does appear so
Recommended Tutorials:
Reply
#5
Honestly I just used Anaconda because it seemed like it had all the tools I needed. Maybe I should just uninstall it and use the native python that Ubuntu comes with.

Conda list does give me a list in the terminal.

Here are the current packages:
_ipyw_jlab_nb_ext_conf    0.1.0            py36he11e457_0  
alabaster                 0.7.10           py36h306e16b_0  
anaconda                  custom                   py36_0  
anaconda-client           1.6.5            py36h19c0dcd_0  
anaconda-navigator        1.6.8            py36h672ccc7_0  
anaconda-project          0.8.0            py36h29abdf5_0  
asn1crypto                0.22.0           py36h265ca7c_1  
astroid                   1.5.3            py36hbdb9df2_0  
astropy                   2.0.2            py36ha51211e_4  
babel                     2.5.0            py36h7d14adf_0  
backports                 1.0              py36hfa02d7e_1  
backports.shutil_get_terminal_size 1.0.0            py36hfea85ff_2  
beautifulsoup4            4.6.0            py36h49b8c8c_1  
bitarray                  0.8.1            py36h5834eb8_0  
bkcharts                  0.2              py36h735825a_0  
blaze                     0.11.3           py36h4e06776_0  
bleach                    2.0.0            py36h688b259_0  
bokeh                     0.12.7           py36h169c5fd_1  
boto                      2.48.0           py36h6e4cd66_1  
bottleneck                1.2.1            py36haac1ea0_0  
ca-certificates           2017.08.26           h1d4fec5_0  
cairo                     1.14.10              h58b644b_4  
certifi                   2017.7.27.1      py36h8b7b77e_0  
cffi                      1.10.0           py36had8d393_1  
chardet                   3.0.4            py36h0f667ec_1  
click                     6.7              py36h5253387_0  
cloudpickle               0.4.0            py36h30f8c20_0  
clyent                    1.2.2            py36h7e57e65_1  
colorama                  0.3.9            py36h489cec4_0  
conda                     4.3.30           py36h5d9f9f4_0  
conda-build               3.0.23           py36h1da9bb0_0  
conda-env                 2.6.0                h36134e3_1  
conda-verify              2.0.0            py36h98955d8_0  
contextlib2               0.5.5            py36h6c84a62_0  
cryptography              2.0.3            py36ha225213_1  
curl                      7.55.1               hcb0b314_2  
cycler                    0.10.0           py36h93f1223_0  
cython                    0.26.1           py36h21c49d0_0  
cytoolz                   0.8.2            py36h708bfd4_0  
dask                      0.15.2           py36h9b48dc4_0  
dask-core                 0.15.2           py36h0f988a8_0  
datashape                 0.5.4            py36h3ad6b5c_0  
dbus                      1.10.22              h3b5a359_0  
decorator                 4.1.2            py36hd076ac8_0  
distributed               1.18.3           py36h73cd4ae_0  
docutils                  0.14             py36hb0f60f5_0  
entrypoints               0.2.3            py36h1aec115_2  
et_xmlfile                1.0.1            py36hd6bccc3_0  
expat                     2.2.4                hc00ebd1_1  
fastcache                 1.0.2            py36h5b0c431_0  
filelock                  2.0.12           py36hacfa1f5_0  
flask                     0.12.2           py36hb24657c_0  
flask-cors                3.0.3            py36h2d857d3_0  
fontconfig                2.12.4               h88586e7_1  
freetype                  2.8                  h52ed37b_0  
get_terminal_size         1.0.0                haa9412d_0  
gevent                    1.2.2            py36h2fe25dc_0  
glib                      2.53.6               hc861d11_1  
glob2                     0.5              py36h2c1b292_1  
gmp                       6.1.2                hb3b607b_0  
gmpy2                     2.0.8            py36h55090d7_1  
graphite2                 1.3.10               hc526e54_0  
greenlet                  0.4.12           py36h2d503a6_0  
gst-plugins-base          1.12.2               he3457e5_0  
gstreamer                 1.12.2               h4f93127_0  
h5py                      2.7.0            py36he81ebca_1  
harfbuzz                  1.5.0                h2545bd6_0  
hdf5                      1.10.1               hb0523eb_0  
heapdict                  1.0.0            py36h79797d7_0  
html5lib                  0.999999999      py36h2cfc398_0  
icu                       58.2                 h211956c_0  
idna                      2.6              py36h82fb2a8_1  
imageio                   2.2.0            py36he555465_0  
imagesize                 0.7.1            py36h52d8127_0  
intel-openmp              2018.0.0             h15fc484_7  
ipykernel                 4.6.1            py36hbf841aa_0  
ipython                   6.1.0            py36hc72a948_1  
ipython_genutils          0.2.0            py36hb52b0d5_0  
ipywidgets                7.0.0            py36h7b55c3a_0  
isort                     4.2.15           py36had401c0_0  
itsdangerous              0.24             py36h93cc618_1  
jbig                      2.1                  hdba287a_0  
jdcal                     1.3              py36h4c697fb_0  
jedi                      0.10.2           py36h552def0_0  
jinja2                    2.9.6            py36h489bce4_1  
jpeg                      9b                   habf39ab_1  
jsonschema                2.6.0            py36h006f8b5_0  
jupyter                   1.0.0            py36h9896ce5_0  
jupyter_client            5.1.0            py36h614e9ea_0  
jupyter_console           5.2.0            py36he59e554_1  
jupyter_core              4.3.0            py36h357a921_0  
jupyterlab                0.27.0           py36h86377d0_2  
jupyterlab_launcher       0.4.0            py36h4d8058d_0  
lazy-object-proxy         1.3.1            py36h10fcdad_0  
libedit                   3.1                  heed3624_0  
libffi                    3.2.1                h4deb6c0_3  
libgcc-ng                 7.2.0                hcbc56d2_1  
libgfortran-ng            7.2.0                h6fcbd8e_1  
libpng                    1.6.32               hda9c8bc_2  
libsodium                 1.0.13               h31c71d8_2  
libssh2                   1.8.0                h8c220ad_2  
libstdcxx-ng              7.2.0                h24385c6_1  
libtiff                   4.0.8                h90200ff_9  
libtool                   2.4.6                hd50d1a6_0  
libxcb                    1.12                 he6ee5dd_2  
libxml2                   2.9.4                h6b072ca_5  
libxslt                   1.1.29               hcf9102b_5  
llvmlite                  0.20.0                   py36_0  
locket                    0.2.0            py36h787c0ad_1  
lxml                      3.8.0            py36h6c6e760_0  
lzo                       2.10                 hc0eb8fc_0  
markupsafe                1.0              py36hd9260cd_1  
matplotlib                2.0.2            py36h2acb4ad_1  
mccabe                    0.6.1            py36h5ad9710_1  
mistune                   0.7.4            py36hbab8784_0  
mkl                       2018.0.0             hb491cac_4  
mkl-service               1.1.2            py36h17a0993_4  
mpc                       1.0.3                hf803216_4  
mpfr                      3.1.5                h12ff648_1  
mpmath                    0.19             py36h8cc018b_2  
msgpack-python            0.4.8            py36hec4c5d1_0  
multipledispatch          0.4.9            py36h41da3fb_0  
navigator-updater         0.1.0            py36h14770f7_0  
nbconvert                 5.3.1            py36hb41ffb7_0  
nbformat                  4.4.0            py36h31c9010_0  
ncurses                   6.0                  h06874d7_1  
networkx                  1.11             py36hfb3574a_0  
nltk                      3.2.4            py36h1a0979f_0  
nose                      1.3.7            py36hcdf7029_2  
notebook                  5.0.0            py36h0b20546_2  
numba                     0.35.0             np113py36_10  
numexpr                   2.6.2            py36hdd3393f_1  
numpy                     1.13.1           py36h5bc529a_2  
numpydoc                  0.7.0            py36h18f165f_0  
odo                       0.5.1            py36h90ed295_0  
olefile                   0.44             py36h79f9f78_0  
openpyxl                  2.4.8            py36h41dd2a8_1  
openssl                   1.0.2l               h9d1a558_3  
packaging                 16.8             py36ha668100_1  
pandas                    0.20.3           py36h842e28d_2  
pandoc                    1.19.2.1             hea2e7c5_1  
pandocfilters             1.4.2            py36ha6701b7_1  
pango                     1.40.11              hedb6d6b_0  
partd                     0.3.8            py36h36fd896_0  
patchelf                  0.9                  hf79760b_2  
path.py                   10.3.1           py36he0c6f6d_0  
pathlib2                  2.3.0            py36h49efa8e_0  
patsy                     0.4.1            py36ha3be15e_0  
pcre                      8.41                 hc71a17e_0  
pep8                      1.7.0            py36h26ade29_0  
pexpect                   4.2.1            py36h3b9d41b_0  
pickleshare               0.7.4            py36h63277f8_0  
pillow                    4.2.1            py36h9119f52_0  
pip                       9.0.1            py36h30f8307_2  
pixman                    0.34.0               ha72d70b_1  
pkginfo                   1.4.1            py36h215d178_1  
ply                       3.10             py36hed35086_0  
prompt_toolkit            1.0.15           py36h17d85b1_0  
psutil                    5.2.2            py36h74c8701_0  
ptyprocess                0.5.2            py36h69acd42_0  
py                        1.4.34           py36h0712aa3_1  
pycodestyle               2.3.1            py36hf609f19_0  
pycosat                   0.6.2            py36h1a0ea17_1  
pycparser                 2.18             py36hf9f622e_1  
pycrypto                  2.6.1            py36h6998063_1  
pycurl                    7.43.0           py36h5e72054_3  
pyflakes                  1.5.0            py36h5510808_1  
pygments                  2.2.0            py36h0d3125c_0  
pylint                    1.7.2            py36h484ab97_0  
pyodbc                    4.0.17           py36h999153c_0  
pyopenssl                 17.2.0           py36h5cc804b_0  
pyparsing                 2.2.0            py36hee85983_1  
pyqt                      5.6.0            py36h0386399_5  
pysocks                   1.6.7            py36hd97a5b1_1  
pytables                  3.4.2            py36hdce54c9_1  
pytest                    3.2.1            py36h11ad3bb_1  
python                    3.6.2               hdfe5801_15  
python-dateutil           2.6.1            py36h88d3b88_1  
pytz                      2017.2           py36hc2ccc2a_1  
pywavelets                0.5.2            py36he602eb0_0  
pyyaml                    3.12             py36hafb9ca4_1  
pyzmq                     16.0.2           py36h3b0cf96_2  
qt                        5.6.2               h974d657_12  
qtawesome                 0.4.4            py36h609ed8c_0  
qtconsole                 4.3.1            py36h8f73b5b_0  
qtpy                      1.3.1            py36h3691cc8_0  
readline                  7.0                  hac23ff0_3  
requests                  2.18.4           py36he2e5f8d_1  
rope                      0.10.5           py36h1f8c17e_0  
ruamel_yaml               0.11.14          py36ha2fb22d_2  
scikit-image              0.13.0           py36had3c07a_1  
scikit-learn              0.19.0           py36h97ac459_2  
scipy                     0.19.1           py36h9976243_3  
seaborn                   0.8.0            py36h197244f_0  
setuptools                36.5.0           py36he42e2e1_0  
simplegeneric             0.8.1            py36h2cb9092_0  
singledispatch            3.4.0.3          py36h7a266c3_0  
sip                       4.18.1           py36h51ed4ed_2  
six                       1.10.0           py36hcac75e4_1  
snowballstemmer           1.2.1            py36h6febd40_0  
sortedcollections         0.5.3            py36h3c761f9_0  
sortedcontainers          1.5.7            py36hdf89491_0  
sphinx                    1.6.3            py36he5f0bdb_0  
sphinxcontrib             1.0              py36h6d0f590_1  
sphinxcontrib-websupport  1.0.1            py36hb5cb234_1  
spyder                    3.2.4            py36hbe6152b_0  
sqlalchemy                1.1.13           py36hfb5efd7_0  
sqlite                    3.20.1               h6d8b0f3_1  
statsmodels               0.8.0            py36h8533d0b_0  
sympy                     1.1.1            py36hc6d1c1c_0  
tblib                     1.3.2            py36h34cf8b6_0  
terminado                 0.6              py36ha25a19f_0  
testpath                  0.3.1            py36h8cadb63_0  
tk                        8.6.7                h5979e9b_1  
toolz                     0.8.2            py36h81f2dff_0  
tornado                   4.5.2            py36h1283b2a_0  
traitlets                 4.3.2            py36h674d592_0  
typing                    3.6.2            py36h7da032a_0  
unicodecsv                0.14.1           py36ha668878_0  
unixodbc                  2.3.4                hc36303a_1  
urllib3                   1.22             py36hbe7ace6_0  
wcwidth                   0.1.7            py36hdf4376a_0  
webencodings              0.5.1            py36h800622e_1  
werkzeug                  0.12.2           py36hc703753_0  
wheel                     0.29.0           py36he7f4e38_1  
widgetsnbextension        3.0.2            py36hd01bb71_1  
wrapt                     1.10.11          py36h28b7045_0  
xlrd                      1.1.0            py36h1db9f0c_1  
xlsxwriter                0.9.8            py36hf41c223_0  
xlwt                      1.3.0            py36h7b00a1f_0  
xz                        5.2.3                h2bcbf08_1  
yaml                      0.1.7                h96e3832_1  
zeromq                    4.2.2                hb0b69da_1  
zict                      0.1.2            py36ha0d441b_0  
zlib                      1.2.11               hfbfcf68_1 

I've got a conda environment for both 2.7 and 3.6

I took the (x) our of xrange for the 3.6 and I'm still getting the same debugging error as I did up top with arrow pointing at the import function. I installed numpy into my conda 3.6 environment using the
conda install --spyder2 numpy
command.
Reply
#6
Quote:I just used Anaconda because it seemed like it had all the tools I needed.
To be honest i would just use the default python install or install python3.x if you wanted that. Anaconda isnt as used by as many people doing just a base install. All you have to do to install packages to OS python is
pip install package_name1 package_name2 etc.
then just link whatever IDE you want with that python interpreter that you installed those packages to.
Recommended Tutorials:
Reply
#7
(Oct-24-2017, 01:10 AM)metulburr Wrote:
Quote:I just used Anaconda because it seemed like it had all the tools I needed.
To be honest i would just use the default python install or install python3.x if you wanted that. Anaconda isnt as used by as many people doing just a base install. All you have to do to install packages to OS python is
pip install package_name1 package_name2 etc.
then just link whatever IDE you want with that python interpreter that you installed those packages to.

I unintalled Anaconda. We'll see if this works a bit smoother. I appreciate all your responses guys.

Hey guys, just wanted to let you know that I got it to work!

metulburr you were totally right on. I got rid of Anaconda, installed pip, and then installed numpy. I decided to use pycharm as my IDE and I was able to specify my projects interpreter. Ran the script and I got an actual output!

Thanks again everyone, you guys are awesome.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020