LikeLike

]]>LikeLike

]]>LikeLike

]]>LikeLike

]]>However, I’m unable to find any practical implications of this concept.

Can anyone help me out on this?

LikeLike

]]>LikeLike

]]>Unlike Mathematica, Python does not issue a warning when I try to redefine a built-in function:

>>> list = [1,2,3]

>>> list({7,8})

Traceback (most recent call last):

File “”, line 1, in

TypeError: ‘list’ object is not callable

This particular error was tricky for me to trace because I implicitly assumed that we cannot casually redefine a built-in function.

I cannot define a set of sets they way I do it in Mathematica, which by the way is also consistent with standard mathematical notation.

>>> {{1}, {2,3}}

Traceback (most recent call last):

File “”, line 1, in

TypeError: unhashable type: ‘set’

I eventually learned that set is implemented as a hash table. As a consequence, we cannot have mutable elements in a set. It did get me to read up on hashing though.

Speaking about mutable objects, there are methods in Python which works via its side effect instead of returning a value. This can cause problems when we use a list comprehension.

>>> [1,2].append(3)

>>> [x.append(3) for x in [[1],[2]]]

[None, None]

>>> lst = [1,2]

>>> lst.append(3)

>>> lst

[1, 2, 3]

We eventually figured out that we should have used + instead of append.

>>> [x+[3] for x in [[1],[2]]]

[[1, 3], [2, 3]]

I’m sure we’ll find more interesting examples as the semester progresses.

LikeLike

]]>LikeLike

]]>I have always been interested by the strong emphasis mathematics has on computer graphics.

Your blog post has certainly deepened my curiosity!

LikeLike

]]>LikeLike

]]>