Saving Ipython script history

%save sessionName linesToKeep

This will save script in line numbers you specify in linesToKeep,for example, 1-20 34-50 64 into a file called “sessionName.py” in your current working directory.

If you are not so specific on which lines you want to keep, you can save everything.

%save sessionName ~0/

This saves everything from the current session, denoted as “~0″ into file “sessionName.py” in your cwd (current working directory).

%save pastSession ~1/

This saves everything from the past session, denoted as “~1” into file “pastSession.py” in your cwd.

Jupyter notebook markdown tips

Tip No. 1- Tip No. 100000: play around and click every button. If you are willing to do this continuously, you will be better than half of the programmers soon, and probably can answer most of the questions in Stackoverflow related to Jupyter Notebook markdown. Go ahead, it won’t break. The worst it could happen is restart. If you have to undo, hit Esc, then ctrl + z.

More

tensorflow upgrade and testing | tensorflow 升级和测试

It has been over a year since I last used tensorflow. Not only library versions have changed, but also the syntax. My old jupyter notebook was throwing errors all over the place this morning. It is time to update everything.

For tensorflow, I am using Python 3.6.3 (I used to use Python 3.5), and numpy 1.16.1. TensorFlow has a few dependencies. numpy is one of them. Note the mnist dataset has 70,000 images.

python -c ‘import tensorflow as tf; print(tf.__version__)

More

An great collection of Python notebooks | Python 笔记本集

Here is a really great collection of Python notebooks with lots and lots of links.  We start with some appetizers:

But there are so many and so much more!! Okay, I am just going to copy (fork) most of this page:

Mathematics

  • Linear algebra with Cython. A tutorial that styles the notebook differently to show that you can produce high-quality typography online with the Notebook. By Carl Vogel.
  • More

Women, men and money

From a dataset on restaurant tip included in the Python seaborn library, we investigate using Python with Jupyter Notebook how much money women and men relatively make, and why.

Most people don’t tip more or less because of server is a man or woman, but we do tip according to tip amount (for equal services).

I will tell you base on data analysis the real reason women make less is mostly because:
1. women work mostly lunch shifts
2. lunch bills are smaller than dinner ones.

Indeed, in every industry, including food services like in the restaurants, women have shouldered more share of the most difficult job in the world: parenting, and dedicated their time and energy to their families.

As a result, they have earned less money than men on average. Let’s give our appreciation to women for their roles in taking care of families!

There is a profound reason why we say “Mother nature”!

Should women work more dinner shifts and leave the important job of taking care of children to …?

That is a difficult question… Take a look at this Jupyter Notebook for the detailed data analysis.
More

Python Data Types | Python 数据类型

Python type NumPy type pandas dtype Usage
str string_, unicode_ object Text
int int_, int8, int16, int32, int64, uint8, uint16, uint32, uint64 int64 Integer numbers
float float_, float16, float32, float64 float64 Floating point numbers
bool bool_ bool True/False values
datetime64[ns] datetime64 Date and time values
timedelta[ns] Differences between two datetimes
category Finite list of text values

Note that what is “str” in Python is called “object” in pandas. This is a potential source of confusion (isn’t everything in Python an object?).

API

Yes, this is still a Magic Math Mandarin blog–but to have tomorrow’s skills means a lot more than just knowing basic math.
API = plugin

This post is a quick note (updates are in progress).

Site that documents most APIs
https://www.programmableweb.com/
More

hash function/ cryptography/ digital signiture

Hash function (散列函數):
Yes, this is still a Magic Math Mandarin blog–but to have tomorrow’s skills means a lot more than just knowing basic math.
A hash function maps arbitrary string of data fix length of bits.

The simplest (a bad one) is to use the ASCii representation of alphabet, sum up the numbers and take mod.   This creates a problem as “cat”, “act” and “tca” are going to be mapped to the same hash.  This problem is called “hash collision” 碰撞.

More

A CS lecture 马克十几年前教的课

It is amazing how much one can learn from this old video, recorded 2 years after Mark Zuckerburg left Harvard. Here is what I remember after listening 5 times:

1. Don’t follow what the big guys are doing. There is so much you can do on your own with technology (find your own problem and get to it)
More