On Tue, Feb 11, 2014 at 4:45 PM, Steven G. Johnson <[email protected]>wrote:
> On Friday, November 30, 2012 7:46:46 AM UTC-5, Stefan Karpinski wrote:
>>
>> To clarify [1 2 3] is a row-matrix, rather than a vector and cannot have
>> an element excised from it.
>
>
> You could delete by reshaping to a column (1d) vector, deleting, and then
> reshaping back. Since the reshaping cheap and in-place, this is reasonably
> efficient.
>
Unfortunately, that doesn't actually work. It used to be that Julia would
throw an error when trying to modify the size of a vector which was an
alias for a multidimensional array (when did that change?). Now, it just
makes a copy:
julia> A = [1 2 3]
1x3 Array{Int64,2}:
1 2 3
julia> pointer(A)
Ptr{Int64} @0x0000000004db2550
julia> a = reshape(A, 3)
3-element Array{Int64,1}:
1
2
3
julia> pointer(a)
Ptr{Int64} @0x0000000004db2550
julia> deleteat!(a, 2)
2-element Array{Int64,1}:
1
3
julia> pointer(a)
Ptr{Int64} @0x000000000396ebd8
julia> a = rand(3)
3-element Array{Float64,1}:
0.91121
0.274773
0.248093
julia> pointer(a)
Ptr{Float64} @0x0000000011df0a60
julia> deleteat!(a, 2)
2-element Array{Float64,1}:
0.91121
0.248093
julia> pointer(a)
Ptr{Float64} @0x0000000011df0a60
Cheers,
Kevin