[Edu-sig] Help with Jupyter Notebook, please?

A Jorge Garcia calcpage at aol.com
Sun Jul 2 23:56:59 EDT 2017


Thanx, Kirby, for all your insightful comments!

Well, I tried! I think I'm spoiled by using Sage all these years where everything is imported for you and it's all based on standard Python. I had no idea that numpy was so different. I thought it just built extra functionality on top of Python. 

BTW, I was initially attracted to Python because it reminded me so much of MATLAB. In MATLAB everything is declared as a matrix whether it be an actual rectangular 2x3 matrix or a square 2x2 matrix or a column vector 3x1 or a row vector 1x4 or even a scalar 1x1! So, my thinking was that everything in Python is based on lists and list comprehensions. 

Another point in Python's favor for a Pythonic math class is that said lists and list operators are great for dealing with sequences and series and hence recursive sequences like we use in Newton's method as well as series that arise in Reiman Sums.

Also, I've been using SageCell for a few years now and forgot about the top down model you refer to when using multiple cells. When using Sage proper or Jupyter, I'll have to be careful about that unless I just use one huge cell!

Thanx for all the constructive criticism. I have a lot of work to do!

Regards,
AJG

⁣Sent from BlueMail ​

On Jul 2, 2017, 10:19 PM, at 10:19 PM, kirby urner <kirby.urner at gmail.com> wrote:
>>
>> https://www.youtube.com/watch?v=fKthpFIV-TU
>>
>>
>Way cool.
>
>I made some notes:
>
>I like how you muddle your way through, showing where you're getting
>confused.  Students looking over your shoulder want to help.  Not
>intimidating.  Shows how we're meant to explore, even as teachers.
>
>You get confused that cells may be Markdown, as shown up top, vs. Code.
>
>Like a spreadsheet, you can write lots of text between code sections. 
>The
>markdown punctuation is a lot like what's used in Wikis, restructured
>text.  Cheat sheet:
>
>https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
>
>(you can embed links, pictures, even Youtubes).
>
>Example:
>http://nbviewer.jupyter.org/github/4dsolutions/Python5/blob/master/Pi%20Day%20Fun.ipynb
>
>Also, it's not that the cells are "isolated" but define objects top to
>bottom, just like a Python module, so yes, if you come in cold and
>start
>running to last cells first, NameError problems are likely.  Running
>them
>all, in order, is a one click option, as you mention.  Nothing wrong
>with
>doing that.
>
>Speadsheets work the same way don't they?  MathCAD does:  you need all
>the
>names mentioned already defined higher up.
>
>Regarding your diff function, one *could* pass a function as an
>argument,
>no problemo, no need for fancy parsing etc. i.e. functions are just
>callable objects e.g.:
>
>def diff( func, x, h=1e-8):
>    return ( func(x+h)-func(x) )/h
>
>then:
>
>def g(x):
>    return x**2 - 2
>
>>>> diff(g, 2)  # passing the function as an argument, accept h default
>
>When you imported * from numpy, you got sin from there.  You sounded
>surprised you could do that without importing it from math.
>
>More evidence of how the * may lead to confusion.
>
>The math version of sin and cos is what you *don't* want, as you're
>trying
>to feed in an np.arange, whereas the math version just accepts scalar
>numbers (degrees or radians)
>
>from numpy import arange, linspace
>
>would be another way to lose the np prefix, short of using a star. 
>Tack on
>sin, cos.
>
>The sin, cos in math are *not* able to handle arange or linspace
>objects,
>so getting these from numpy is what you needed all along.  Might not
>have
>needed math at all.  But then explain how numpy is so vary oriented
>towards
>array processing.
>
>from numpy import arange, sin  # this will work
>t = arange(0, 2, 0.1)
>sin(t)
>array([ 0.        ,  0.09983342,  0.19866933,  0.29552021,  0.38941834,
>        0.47942554,  0.56464247,  0.64421769,  0.71735609,  0.78332691,
>        0.84147098,  0.89120736,  0.93203909,  0.96355819,  0.98544973,
>       0.99749499,  0.9995736 ,  0.99166481,  0.97384763,  0.94630009])
>
>
>from math import sin  # uh oh, this import of sin gets in the way
>sin(t)
>
>Traceback (most recent call last):
>  Python Shell, prompt 8, line 1
>builtins.TypeError: only length-1 arrays can be converted to Python
>scalars
>
>Note that in Python3, range(a, b) creates a "range type object", not a
>list, which is why you don't see the output as a list until the list
>comprehension.
>
>list(range(a,b)) will always get you the list representation.
>
>Thanks again!
>
>Kirby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20170702/3d340fc6/attachment-0001.html>


More information about the Edu-sig mailing list