Vector of vector re-size

Vector of vector re-size



So I have two vector of vectors like:



matchings_vec = VectorVectorVectorVectorAny(num_tilt1)



Minfoall_vec = VectorVectorVectorVectorVectorVectorFloat64(num_tilt1)



I defined it as:


matchings_vec = [VectorAny() for i in 1:num_tilt1]
Minfoall_vec = [VectorFloat64() for i in 1:num_tilt1]



Then I am trying to resize the inner vectors like:


for tt = 1:num_tilt1
t_tt = t[tt] #; t1 = t_tt; t2 = 1;
if t_tt == 1
num_rot1 = 1
else
num_rot1 = round(Int, num_rot_t2 * t_tt/2)
if rem.(num_rot1, 2) == 1.0
num_rot1 += 1
end
num_rot1 /= 2
end
num_rot1 = round(Int, num_rot1)
#resize!(matchings_vec[tt], num_rot1)
matchings_vec[tt] = VectorAny(num_rot1)
#resize!(Minfoall_vec[tt], num_rot1)
Minfoall_vec[tt] = VectorFloat64(num_rot1)
for rr = 1:num_rot1
num_tilt2 = round(Int, num_tilt2)
#resize!(matchings_vec[tt][rr], num_tilt2)
matchings_vec[tt][rr] = VectorAny(num_tilt2)
#resize!(Minfoall_vec[tt][rr], num_tilt2)
Minfoall_vec[tt][rr] = VectorFloat64(num_tilt2)
for tt2 = 1:num_tilt2
t_im2 = t[tt2]
#t_im2_1 = t_im2; t_im2_2 = 1;
if t_im2 == 1
num_rot1_2 = 1
else
num_rot1_2 = round(Int, num_rot_t2 * t_im2/2)
if rem.(num_rot1_2, 2) == 1.0
num_rot1_2 += 1
end
num_rot1_2 /= 2
end
num_rot1_2 = round(Int, num_rot1_2)
#resize!(matchings_vec[tt][rr][tt2], num_rot1_2)
matchings_vec[tt][rr][tt2] = VectorAny(num_rot1_2)
#resize!(Minfoall_vec[tt][rr][tt2], num_rot1_2)
Minfoall_vec[tt][rr][tt2] = VectorFloat64(num_rot1_2)
end
end
end



I am getting this error:



MethodError: Cannot convert an object of type ArrayFloat64,1 to an
object of type Float64 This may have arisen from a call to the
constructor Float64(...), since type constructors fall back to convert
methods.


convert



Stacktrace: [1] setindex!(::ArrayFloat64,1, ::ArrayFloat64,1,
::Int64) at ./array.jl:578 [2] macro expansion at ./In[32]:22
[inlined] [3] anonymous at ./:?



Can you suggest what I am doing wrong? Thanks!





What is num_tilt2? It seems to just appear out of nowhere in the example code you provide. I'm guessing it is of type Float64 and so the error is caused by VectorAny(num_tilt2), because Julia doesn't automatically convert scalar types to arrays. So VectorAny(0.0) will cause an error, but VectorAny([0.0]) will not (although I'm not sure why you would specifically want a VectorAny when you could have a VectorFloat64... it isn't clear to me what you're trying to do with this code)
– Colin T Bowers
Aug 20 at 4:38



num_tilt2


Float64


VectorAny(num_tilt2)


VectorAny(0.0)


VectorAny([0.0])


VectorAny


VectorFloat64





Hi @ColinTBowers, Sorry I edited it and getting the error above
– Isai
Aug 20 at 4:46





I think you think that VectorAny(num_rot1) creates a vector of length num_rot1. It doesn't. As per my comment above, it will throw an error if num_rot1 is Int or Float64 (this is a deliberate design choice). Just use something like zeros(Float64, num_rot1) to initialize a VectorFloat64 of length num_rot1. Also, I don't know why you're bothering with all the resizing. As near as I can tell, you could remove every resize! line and still get the same outcome.
– Colin T Bowers
Aug 20 at 6:02


VectorAny(num_rot1)


num_rot1


num_rot1


Int


Float64


zeros(Float64, num_rot1)


VectorFloat64


num_rot1


resize!









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

ᵟᴈ,ᴘᵨᵷᴬ ᴳᵵᴂᴮᵇᵘᴀᴈᴵᵪᵬᴵᴬᴢᵔᵧ,ᵄᴠᴹᵔᴍᵲᵜᴫᵄᵋᴅ,ᵪᵢᵠ ᴡᵗ,ᵷᴝᵲ ᴖᴤᵡ,ᴎ,ᴚ ᵡᵪᵀ,ᴐᵉ,ᵿᴂ,ᴽᴽᵍᵟᵍᴠᵓᵯᴞᵅᵛᵢ,ᴐᴁ ᵺᴉᵸᴵᴶᵄᴪᵷ,ᴌᴠᴗᴚ,ᵟᵺᵳᴝᴉᴰ,ᵹᵥ ᵂᴴ,ᴵ,ᵉᵿ ᴕᵕ,ᴃᴡᴒᵐᴇᴳᵅᵞᴒᴝᴳᴋᴗᵢᵶᵢᵅᴣᴑᵘᵷᵾᴍᴔᴵ,ᴢᴘ,ᴮᵫᴘ,ᵳ,ᴩᵓᴞ