You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I know you guys have a vec function that essentially works like this
vec(a::AbstractArray) = reshape(a,length(a))
vec(a::AbstractVector) = a
I find myself having to write an hvec function to create horizontal vectors out of arrays for convenience.
hvec(x::AbstractArray) = reshape(x, 1, :)
Using something like vec(x)' only works if x is numeric. When trying to broadcast an operation to operate on every pair of elements in x and y to form a matrix, it's very helpful to be able to quickly construct a vertical vector for x and a horizontal one for y.
M = some_scalar_operation.( vec(x), hvec(y) )
Do you think it would be reasonable to put hvec into base or make vec(x)' work for vectors of all types?
The text was updated successfully, but these errors were encountered:
This won't happen, it was decided a while ago that this syntax (') would be for linear algebra, and not for reshaping of arrays of arbitrary objects (see e.g. #20978 & #21037).
As a sidenote, be careful with the ' operator: it's a complex transpose, and will therefore conjugate each element of the vector.
Hello, I know you guys have a vec function that essentially works like this
vec(a::AbstractArray) = reshape(a,length(a))
vec(a::AbstractVector) = a
I find myself having to write an hvec function to create horizontal vectors out of arrays for convenience.
hvec(x::AbstractArray) = reshape(x, 1, :)
Using something like vec(x)' only works if x is numeric. When trying to broadcast an operation to operate on every pair of elements in x and y to form a matrix, it's very helpful to be able to quickly construct a vertical vector for x and a horizontal one for y.
M = some_scalar_operation.( vec(x), hvec(y) )
Do you think it would be reasonable to put hvec into base or make vec(x)' work for vectors of all types?
The text was updated successfully, but these errors were encountered: