1

I have a question regarding building a bunch of arrays off of a single array.

Suppose I have myarr = [2,3]. I want to build an array of arrays that contains elements that are at least half as big (going up to some limit I have defined maxSize as a single element, but leaves the others unchanged) and with steps defined (e.g. stepsize=0.5). For example suppose maxsize = 5, the first element in myarr is 2 and so I want to create:

[1,3]
[1.5,3]
[2,3] # Ideally I should exclude myarr...
[2,1.5]
[2,2]
[2,2.5]
[2,3]

Is there anyway to construct this?

1
  • It's unclear to me what you are trying to do. Could you show the entire output you are looking for? (Also, you open a parenthesis that you never close, so I'm not sure how to interpret the main sentence describing what you want.) Commented Nov 22, 2020 at 3:34

1 Answer 1

2

It seems you want

julia> [(x = Float64.(myarr); x[idx] = v; x) for idx in 1:length(myarr) for v in myarr[idx]/2:stepsize:min(maxsize, myarr[idx]) if v ≠ myarr[idx]]
5-element Array{Array{Float64,1},1}:
 [1.0, 3.0]
 [1.5, 3.0]
 [2.0, 1.5]
 [2.0, 2.0]
 [2.0, 2.5]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.