findall() or filter() functions with multiple conditions in julia 1.0.3












0















I am trying to convert following python codes to julia 1.0.3



    from numpy import *
xl,xr,yl,yr = 0,1,0,1
xs,ys = linspace(xl,xr,N),linspace(yl,yr,N)

x,y = np.meshgrid(xs,ys)
data=column_stack((ravel(x),ravel(y)))
idx1 = where((data[:,0]==xl) | (data[:,0]==xr) | (data[:,1]==yl) | (data[:,1]==yr))


I could not convert last row of the above codes. I came across findall() and filter() functions but could not use them properly in my case










share|improve this question

























  • Can you explain what your code should do? Not everyone is familiar with numpy, and this where line is not so easy to interpret.

    – phg
    Dec 28 '18 at 19:44
















0















I am trying to convert following python codes to julia 1.0.3



    from numpy import *
xl,xr,yl,yr = 0,1,0,1
xs,ys = linspace(xl,xr,N),linspace(yl,yr,N)

x,y = np.meshgrid(xs,ys)
data=column_stack((ravel(x),ravel(y)))
idx1 = where((data[:,0]==xl) | (data[:,0]==xr) | (data[:,1]==yl) | (data[:,1]==yr))


I could not convert last row of the above codes. I came across findall() and filter() functions but could not use them properly in my case










share|improve this question

























  • Can you explain what your code should do? Not everyone is familiar with numpy, and this where line is not so easy to interpret.

    – phg
    Dec 28 '18 at 19:44














0












0








0








I am trying to convert following python codes to julia 1.0.3



    from numpy import *
xl,xr,yl,yr = 0,1,0,1
xs,ys = linspace(xl,xr,N),linspace(yl,yr,N)

x,y = np.meshgrid(xs,ys)
data=column_stack((ravel(x),ravel(y)))
idx1 = where((data[:,0]==xl) | (data[:,0]==xr) | (data[:,1]==yl) | (data[:,1]==yr))


I could not convert last row of the above codes. I came across findall() and filter() functions but could not use them properly in my case










share|improve this question
















I am trying to convert following python codes to julia 1.0.3



    from numpy import *
xl,xr,yl,yr = 0,1,0,1
xs,ys = linspace(xl,xr,N),linspace(yl,yr,N)

x,y = np.meshgrid(xs,ys)
data=column_stack((ravel(x),ravel(y)))
idx1 = where((data[:,0]==xl) | (data[:,0]==xr) | (data[:,1]==yl) | (data[:,1]==yr))


I could not convert last row of the above codes. I came across findall() and filter() functions but could not use them properly in my case







julia-lang






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 19:36







user1772257

















asked Dec 28 '18 at 17:53









user1772257user1772257

178212




178212













  • Can you explain what your code should do? Not everyone is familiar with numpy, and this where line is not so easy to interpret.

    – phg
    Dec 28 '18 at 19:44



















  • Can you explain what your code should do? Not everyone is familiar with numpy, and this where line is not so easy to interpret.

    – phg
    Dec 28 '18 at 19:44

















Can you explain what your code should do? Not everyone is familiar with numpy, and this where line is not so easy to interpret.

– phg
Dec 28 '18 at 19:44





Can you explain what your code should do? Not everyone is familiar with numpy, and this where line is not so easy to interpret.

– phg
Dec 28 '18 at 19:44












1 Answer
1






active

oldest

votes


















1














I understand you want data to hold all pairs you can create from elements of xs and ys and select the indices of elements of data that are on the border to idx1. If this is the case this is how I would implement it in Julia:



n=11
xl, xr, yl, yr = 0,1,0,1
xs, ys = range(xl, stop=xr, length=n), range(xl, stop=xr, length=n)
data = [(x,y) for y in ys for x in xs]
idx1 = findall(((x,y),) -> x in (xl,xr) || y in (yl, yr), data)


If you want data to be a matrix not a vector you could do:



data2 = reduce(vcat, [x y] for y in ys for x in xs)
idx12 = filter(i -> data2[i,1] in (xl,xr) || data2[i,2] in (yl, yr), axes(data2, 1))


but in this case for me it would be more natural in Julia to use a vector of tuples rather than a matrix.



You can also consider using Iterators.product function to generate data like this vec(collect(Iterators.product(xs, ys))).






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962443%2ffindall-or-filter-functions-with-multiple-conditions-in-julia-1-0-3%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I understand you want data to hold all pairs you can create from elements of xs and ys and select the indices of elements of data that are on the border to idx1. If this is the case this is how I would implement it in Julia:



    n=11
    xl, xr, yl, yr = 0,1,0,1
    xs, ys = range(xl, stop=xr, length=n), range(xl, stop=xr, length=n)
    data = [(x,y) for y in ys for x in xs]
    idx1 = findall(((x,y),) -> x in (xl,xr) || y in (yl, yr), data)


    If you want data to be a matrix not a vector you could do:



    data2 = reduce(vcat, [x y] for y in ys for x in xs)
    idx12 = filter(i -> data2[i,1] in (xl,xr) || data2[i,2] in (yl, yr), axes(data2, 1))


    but in this case for me it would be more natural in Julia to use a vector of tuples rather than a matrix.



    You can also consider using Iterators.product function to generate data like this vec(collect(Iterators.product(xs, ys))).






    share|improve this answer






























      1














      I understand you want data to hold all pairs you can create from elements of xs and ys and select the indices of elements of data that are on the border to idx1. If this is the case this is how I would implement it in Julia:



      n=11
      xl, xr, yl, yr = 0,1,0,1
      xs, ys = range(xl, stop=xr, length=n), range(xl, stop=xr, length=n)
      data = [(x,y) for y in ys for x in xs]
      idx1 = findall(((x,y),) -> x in (xl,xr) || y in (yl, yr), data)


      If you want data to be a matrix not a vector you could do:



      data2 = reduce(vcat, [x y] for y in ys for x in xs)
      idx12 = filter(i -> data2[i,1] in (xl,xr) || data2[i,2] in (yl, yr), axes(data2, 1))


      but in this case for me it would be more natural in Julia to use a vector of tuples rather than a matrix.



      You can also consider using Iterators.product function to generate data like this vec(collect(Iterators.product(xs, ys))).






      share|improve this answer




























        1












        1








        1







        I understand you want data to hold all pairs you can create from elements of xs and ys and select the indices of elements of data that are on the border to idx1. If this is the case this is how I would implement it in Julia:



        n=11
        xl, xr, yl, yr = 0,1,0,1
        xs, ys = range(xl, stop=xr, length=n), range(xl, stop=xr, length=n)
        data = [(x,y) for y in ys for x in xs]
        idx1 = findall(((x,y),) -> x in (xl,xr) || y in (yl, yr), data)


        If you want data to be a matrix not a vector you could do:



        data2 = reduce(vcat, [x y] for y in ys for x in xs)
        idx12 = filter(i -> data2[i,1] in (xl,xr) || data2[i,2] in (yl, yr), axes(data2, 1))


        but in this case for me it would be more natural in Julia to use a vector of tuples rather than a matrix.



        You can also consider using Iterators.product function to generate data like this vec(collect(Iterators.product(xs, ys))).






        share|improve this answer















        I understand you want data to hold all pairs you can create from elements of xs and ys and select the indices of elements of data that are on the border to idx1. If this is the case this is how I would implement it in Julia:



        n=11
        xl, xr, yl, yr = 0,1,0,1
        xs, ys = range(xl, stop=xr, length=n), range(xl, stop=xr, length=n)
        data = [(x,y) for y in ys for x in xs]
        idx1 = findall(((x,y),) -> x in (xl,xr) || y in (yl, yr), data)


        If you want data to be a matrix not a vector you could do:



        data2 = reduce(vcat, [x y] for y in ys for x in xs)
        idx12 = filter(i -> data2[i,1] in (xl,xr) || data2[i,2] in (yl, yr), axes(data2, 1))


        but in this case for me it would be more natural in Julia to use a vector of tuples rather than a matrix.



        You can also consider using Iterators.product function to generate data like this vec(collect(Iterators.product(xs, ys))).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 28 '18 at 20:39

























        answered Dec 28 '18 at 20:24









        Bogumił KamińskiBogumił Kamiński

        12.3k11120




        12.3k11120






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962443%2ffindall-or-filter-functions-with-multiple-conditions-in-julia-1-0-3%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas