by eigenspace · 7y ago · 0 comments
[1 2 3]'
but that will give you the (lazy) hermitian adjoint of the column vector, not a column matrix. julia> [1 2 3]' isa Matrix
false
Instead, if you really need a true (n, 1) matrix you should 1) not use adjoint because that will also take complex conjugates (unless that's what you wanted) and 2) use collect to turn the lazy transpose (or adjoint) into a true matrix julia> collect(transpose([1 2 3]))
3×1 Array{Int64,2}:
1
2
3
However, you almost never need to do this sort of thing and you should be fine using either transpose on a row vector or just using a real column vector.Also, near the end they talk about closures but don't actually show any closures unless one is to assume the code snippets they're showing are actually inside a function body themselves.
If you only ever work in R then technically that'd be fine (though notationally awkward). But that's not a good habit to keep since it would introduce pretty insidious bugs if you ever take the adjoint of a complex matrix intending to take the transpose.
There’s no math or physics equation here with objects transforming under an adjoint representation, it’s just a constructor.
The only guaranteed way to ensure that a free variable in python function scope (it's not a closure) does not change is to pass it explicitly as a default value.
a = 1
def function(x, a=a):
return x + a
That will work in loops. Otherwise what you are really writing is a = 1
def function(x):
return x + the_last_value_a_obtains_in_this_scope
a = 2
assert function(1) == 3What? It's not a big fat lie, it's the exact truth. The same truth you'd get in any language, even Scheme:
> (define a 1)
> (define (f) a)
> (f)
1
> (define a 2)
> (f)
2
That's just how closures work...Your example is true at the top level in scheme, but semantics in top (REPL) are different (at least in Racket [0, 1]). In a source file you have to explicitly use set! to mutate a so it is harder to shoot yourself in the foot. In theory the implementation of closures is the same, but in python's case you are free to mutate yourself into unexpected situations. Whereas I'm actually not even sure it is possible to construct a situation in scheme (not at the top level) where you could induce a situation similar to the one in python.
0. https://gist.github.com/samth/3083053 1. https://groups.google.com/d/msg/racket-users/0BLHm18YUkc/BwQ...
In many cases, the "FP paradigm" is very sensible and makes closures safe to work with and easy to reason about, especially in contexts where concurrently running processes could alter the memory underneath you.
iex(1)> a = 1
1
iex(2)> f = fn x -> x + a end
#Function<7.91303403/1 in :erl_eval.expr/5>
iex(3)> f.(1)
2
iex(4)> a = 2
2
iex(5)> f.(1)
2julia> a = 1
1
julia> function foo(x) x+ a end
foo (generic function with 1 method)
julia> foo(2)
3
julia> a = 2
2
julia> foo(2)
4