Link:
index_to_word=[1,2,1,2,3]
>>> dict([(w,i) for i,w in enumerate(index_to_word)])
{1: 2, 2: 3, 3: 4}
>>> enumerate(index_to_word)
<enumerate object at 0x7f15df7d9870>
>>> [(w,i) for i,w in enumerate(index_to_word)]
[(1, 0), (2, 1), (1, 2), (2, 3), (3, 4)]
Note:
enumerate():
A new built-in function, enumerate(), will make certain loops a bit clearer.enumerate(thing)
, where thing is either an iterator or a sequence, returns a iterator that will return (0,thing[0])
, (1, thing[1])
, (2, thing[2])
, and so forth.A common idiom to change every element of a list looks like this:
for i in range(len(L)): item = L[i] # ... compute some result based on item ... L[i] = result
for i, item in enumerate(L): # ... compute some result based on item ... L[i] = result
ERROR:
To start the Jupyter Notebook:
# Clone the repo
git clone https://github.com/dennybritz/rnn-tutorial-rnnlm
cd rnn-tutorial-rnnlm
# Create a new virtual environment (optional, but recommended)
virtualenv venv
source venv/bin/activate
I have trouble to run the following
# Install requirements
pip install -r requirements.txt
# Start the notebook server
jupyter notebook
pip install -r requirements.txt
It give errors:
Could not find a version that satisfies the requirement functools32==3.2.3.post2 (from -r requirements.txt (line 6)) (from versions: 3.2.3-1, 3.2.3-1, 3.2.3-2, 3.2.3-2)
Cleaning up...
No distributions matching the version for functools32==3.2.3.post2 (from -r requirements.txt (line 6))
Storing debug log for failure in /home/username/.pip/pip.log
Then I go to the following place:
https://pypi.python.org/packages/source/f/functools32/functools32-3.2.3-2.tar.gz#md5=09f24ffd9af9f6cd0f63cb9f4e23d4b2
to download functools32-3.2.3-2.tar.gz
after untar,
use the following command to
sudo python setup.py install
It actually install sth under the following dir:
/usr/local/lib/python2.7/dist-packages/functools32
Solution:
Following the official website of:
http://jupyter.readthedocs.org/en/latest/install.html#existing-python-new-jupyter
pip install -U jupyter
No comments:
Post a Comment