I’m a bit surprised we don’t have a method for squeeze that works like
function Base.squeeze(A)
sqzindx = find(collect(size(A)) .== 1)
if isempty(sqzindx)
return A
else
return squeeze(A, tuple(sqzindx...))
end
end
which simply squeezes out all singleton dimensions.
-Ethan
On Monday, September 8, 2014 10:52:22 AM UTC-7, Ethan Anderes wrote:
I think this is what you want:
>
> squeeze(A[1,:,:,:],1)
>
>
> On Monday, September 8, 2014 10:39:47 AM UTC-7, Jude wrote:
>
> Hi,
>>
>> I was just wondering how to pull out only part of a matrix, for example,
>> if I have a matrix of dimension (2,5,3,8) and I want to get the
>> corresponding matrix for when the first dimension is set at 1, for example,
>> A = ones(2,5,3,8) and I want A[1,:,:,:] ? So ultimately I end up with a 3
>> dimensional matrix and not 4? In Matlab I would use c(:,:,:)= A(1,:,:,:)
>> but when I try something similar in Julia, eg, c = A[1,:,:,:] I get a
>> 1x5x3x8 array but I just want 5x3x8?
>>
>> Thanks,
>> Jude
>>
>>
>