How to use pandas.rolling().mean for 3D input array?How can I represent an 'Enum' in Python?How to flush output of print function?How to iterate over rows in a DataFrame in Pandas?Asking the user for input until they give a valid responsePandas Series.filter.values returning different type than numpy arrayWhat does “SyntaxError: Missing parentheses in call to 'print'” mean in Python?masking a series with a boolean arrayHow do numpy functions operate on pandas objects internally?How do pandas Rolling objects work?Efficient rolling trimmed mean with Python

What's a moment that's more impactful on a reread called?

How to check the quality of an audio sample?

Why does Hellboy file down his horns?

Cubic programming and beyond?

Repeating redundant information after dialogues, to avoid or not?

Shortest distance around a pyramid

Replacements for swear words

What can the U.S. government do to prevent powerful people to get extremely favorable plea bargain deals like Jeff Epstein?

What's the fastest way to get Hard To Borrow (HTB) stocks?

Is the premise of Robert Mueller about how a sitting President cannot be indicted imply that a sitting President is above the law?

Password maker in c#

Why isn't there research to build a standard lunar, or Martian mobility platform?

Is killing off one of my queer characters homophobic?

How can I deal with a player trying to insert real-world mythology into my homebrew setting?

Referring to different instances of the same character in time travel

Would letting a multiclass character rebuild their character to be single-classed be game-breaking?

Can I intentionally omit previous work experience or pretend it doesn't exist when applying for jobs?

Cops: The Hidden OEIS Substring

What would the EU do if an EU member declared war on another EU member?

How might the United Kingdom become a republic?

Filtering fine silt/mud from water (not necessarily bacteria etc.)

Is this floating-point optimization allowed?

Why do players in the past play much longer tournaments than today's top players?

Why would guns not work in the dungeon?



How to use pandas.rolling().mean for 3D input array?


How can I represent an 'Enum' in Python?How to flush output of print function?How to iterate over rows in a DataFrame in Pandas?Asking the user for input until they give a valid responsePandas Series.filter.values returning different type than numpy arrayWhat does “SyntaxError: Missing parentheses in call to 'print'” mean in Python?masking a series with a boolean arrayHow do numpy functions operate on pandas objects internally?How do pandas Rolling objects work?Efficient rolling trimmed mean with Python






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















For 1D I can use:



a=np.array([1,2,3,4])
b=pandas.Series(a).rolling(window=3,center=True).mean()


But the problem is, if I have array a, in 3D then using this method gives error



Exception: Data must be 1-dimensional


The code which I used is:



t[:,:,0]=(pd.Series(imgg[:,:,0:4]).rolling(window=[1,1,3],center=True).mean())


Here imgg is 3D numpy array.



What else I tried:



I also tried the old function rolling_mean i.e. pd.rolling_mean(a,4,center=True), but it is also not working, it gives error:



AssertionError: cannot support ndim > 2 for ndarray compat









share|improve this question
























  • 3d input array, lot of way to show a 3d array... could you precise by an example the initial 3d array and the expected output..

    – Frenchy
    Mar 26 at 5:42












  • I took one 3D image and converted it into np array using np.array(img.dataobj).

    – Prvt_Yadv
    Mar 26 at 6:03












  • the rolling number is the same for all Dimensions?

    – Frenchy
    Mar 26 at 6:28











  • I used different values in window i just want to reduce depth of array. So height width are 1 1 in widow .

    – Prvt_Yadv
    Mar 26 at 6:29












  • If i'm not getting it wrong, you want to compute the rolling mean only on the the 3rd dimension of imgg?

    – kerwei
    Mar 26 at 6:52

















0















For 1D I can use:



a=np.array([1,2,3,4])
b=pandas.Series(a).rolling(window=3,center=True).mean()


But the problem is, if I have array a, in 3D then using this method gives error



Exception: Data must be 1-dimensional


The code which I used is:



t[:,:,0]=(pd.Series(imgg[:,:,0:4]).rolling(window=[1,1,3],center=True).mean())


Here imgg is 3D numpy array.



What else I tried:



I also tried the old function rolling_mean i.e. pd.rolling_mean(a,4,center=True), but it is also not working, it gives error:



AssertionError: cannot support ndim > 2 for ndarray compat









share|improve this question
























  • 3d input array, lot of way to show a 3d array... could you precise by an example the initial 3d array and the expected output..

    – Frenchy
    Mar 26 at 5:42












  • I took one 3D image and converted it into np array using np.array(img.dataobj).

    – Prvt_Yadv
    Mar 26 at 6:03












  • the rolling number is the same for all Dimensions?

    – Frenchy
    Mar 26 at 6:28











  • I used different values in window i just want to reduce depth of array. So height width are 1 1 in widow .

    – Prvt_Yadv
    Mar 26 at 6:29












  • If i'm not getting it wrong, you want to compute the rolling mean only on the the 3rd dimension of imgg?

    – kerwei
    Mar 26 at 6:52













0












0








0








For 1D I can use:



a=np.array([1,2,3,4])
b=pandas.Series(a).rolling(window=3,center=True).mean()


But the problem is, if I have array a, in 3D then using this method gives error



Exception: Data must be 1-dimensional


The code which I used is:



t[:,:,0]=(pd.Series(imgg[:,:,0:4]).rolling(window=[1,1,3],center=True).mean())


Here imgg is 3D numpy array.



What else I tried:



I also tried the old function rolling_mean i.e. pd.rolling_mean(a,4,center=True), but it is also not working, it gives error:



AssertionError: cannot support ndim > 2 for ndarray compat









share|improve this question
















For 1D I can use:



a=np.array([1,2,3,4])
b=pandas.Series(a).rolling(window=3,center=True).mean()


But the problem is, if I have array a, in 3D then using this method gives error



Exception: Data must be 1-dimensional


The code which I used is:



t[:,:,0]=(pd.Series(imgg[:,:,0:4]).rolling(window=[1,1,3],center=True).mean())


Here imgg is 3D numpy array.



What else I tried:



I also tried the old function rolling_mean i.e. pd.rolling_mean(a,4,center=True), but it is also not working, it gives error:



AssertionError: cannot support ndim > 2 for ndarray compat






python-3.x pandas rolling-average






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 6:50







Prvt_Yadv

















asked Mar 26 at 4:40









Prvt_YadvPrvt_Yadv

1132 silver badges13 bronze badges




1132 silver badges13 bronze badges












  • 3d input array, lot of way to show a 3d array... could you precise by an example the initial 3d array and the expected output..

    – Frenchy
    Mar 26 at 5:42












  • I took one 3D image and converted it into np array using np.array(img.dataobj).

    – Prvt_Yadv
    Mar 26 at 6:03












  • the rolling number is the same for all Dimensions?

    – Frenchy
    Mar 26 at 6:28











  • I used different values in window i just want to reduce depth of array. So height width are 1 1 in widow .

    – Prvt_Yadv
    Mar 26 at 6:29












  • If i'm not getting it wrong, you want to compute the rolling mean only on the the 3rd dimension of imgg?

    – kerwei
    Mar 26 at 6:52

















  • 3d input array, lot of way to show a 3d array... could you precise by an example the initial 3d array and the expected output..

    – Frenchy
    Mar 26 at 5:42












  • I took one 3D image and converted it into np array using np.array(img.dataobj).

    – Prvt_Yadv
    Mar 26 at 6:03












  • the rolling number is the same for all Dimensions?

    – Frenchy
    Mar 26 at 6:28











  • I used different values in window i just want to reduce depth of array. So height width are 1 1 in widow .

    – Prvt_Yadv
    Mar 26 at 6:29












  • If i'm not getting it wrong, you want to compute the rolling mean only on the the 3rd dimension of imgg?

    – kerwei
    Mar 26 at 6:52
















3d input array, lot of way to show a 3d array... could you precise by an example the initial 3d array and the expected output..

– Frenchy
Mar 26 at 5:42






3d input array, lot of way to show a 3d array... could you precise by an example the initial 3d array and the expected output..

– Frenchy
Mar 26 at 5:42














I took one 3D image and converted it into np array using np.array(img.dataobj).

– Prvt_Yadv
Mar 26 at 6:03






I took one 3D image and converted it into np array using np.array(img.dataobj).

– Prvt_Yadv
Mar 26 at 6:03














the rolling number is the same for all Dimensions?

– Frenchy
Mar 26 at 6:28





the rolling number is the same for all Dimensions?

– Frenchy
Mar 26 at 6:28













I used different values in window i just want to reduce depth of array. So height width are 1 1 in widow .

– Prvt_Yadv
Mar 26 at 6:29






I used different values in window i just want to reduce depth of array. So height width are 1 1 in widow .

– Prvt_Yadv
Mar 26 at 6:29














If i'm not getting it wrong, you want to compute the rolling mean only on the the 3rd dimension of imgg?

– kerwei
Mar 26 at 6:52





If i'm not getting it wrong, you want to compute the rolling mean only on the the 3rd dimension of imgg?

– kerwei
Mar 26 at 6:52












1 Answer
1






active

oldest

votes


















1














Okay, hopefully this is what you need.



I think you can try to split up the arrays first, instead of trying to work on a 3-dimensional array - since we know that it works on 1D.



import pandas as pd

imgg = [(1,2,1),(2,3,3),(4,1,2),(5,3,2),(6,2,1),(2,3,4),(5,6,2)]

>>>imgg
0 1 2
0 1 2 1
1 2 3 3
2 4 1 2
3 5 3 2
4 6 2 1
5 2 3 4
6 5 6 2

x = []
y = []
d = []

# Split into components
for img in imgg:
x.append(img[0])
y.append(img[1])
d.append(img[2])

# Compute rolling mean
dm = pd.Series(d).rolling(window=3,center=True).mean()

# Stitch them back to form your desired dataframe
data = [k for k in zip(x,y,dm)]
df = pd.DataFrame(data)

>>>df
0 1 2
0 1 2 NaN
1 2 3 2.000000
2 4 1 2.333333
3 5 3 1.666667
4 6 2 2.333333
5 2 3 2.333333
6 5 6 NaN





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%2f55349964%2fhow-to-use-pandas-rolling-mean-for-3d-input-array%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














    Okay, hopefully this is what you need.



    I think you can try to split up the arrays first, instead of trying to work on a 3-dimensional array - since we know that it works on 1D.



    import pandas as pd

    imgg = [(1,2,1),(2,3,3),(4,1,2),(5,3,2),(6,2,1),(2,3,4),(5,6,2)]

    >>>imgg
    0 1 2
    0 1 2 1
    1 2 3 3
    2 4 1 2
    3 5 3 2
    4 6 2 1
    5 2 3 4
    6 5 6 2

    x = []
    y = []
    d = []

    # Split into components
    for img in imgg:
    x.append(img[0])
    y.append(img[1])
    d.append(img[2])

    # Compute rolling mean
    dm = pd.Series(d).rolling(window=3,center=True).mean()

    # Stitch them back to form your desired dataframe
    data = [k for k in zip(x,y,dm)]
    df = pd.DataFrame(data)

    >>>df
    0 1 2
    0 1 2 NaN
    1 2 3 2.000000
    2 4 1 2.333333
    3 5 3 1.666667
    4 6 2 2.333333
    5 2 3 2.333333
    6 5 6 NaN





    share|improve this answer



























      1














      Okay, hopefully this is what you need.



      I think you can try to split up the arrays first, instead of trying to work on a 3-dimensional array - since we know that it works on 1D.



      import pandas as pd

      imgg = [(1,2,1),(2,3,3),(4,1,2),(5,3,2),(6,2,1),(2,3,4),(5,6,2)]

      >>>imgg
      0 1 2
      0 1 2 1
      1 2 3 3
      2 4 1 2
      3 5 3 2
      4 6 2 1
      5 2 3 4
      6 5 6 2

      x = []
      y = []
      d = []

      # Split into components
      for img in imgg:
      x.append(img[0])
      y.append(img[1])
      d.append(img[2])

      # Compute rolling mean
      dm = pd.Series(d).rolling(window=3,center=True).mean()

      # Stitch them back to form your desired dataframe
      data = [k for k in zip(x,y,dm)]
      df = pd.DataFrame(data)

      >>>df
      0 1 2
      0 1 2 NaN
      1 2 3 2.000000
      2 4 1 2.333333
      3 5 3 1.666667
      4 6 2 2.333333
      5 2 3 2.333333
      6 5 6 NaN





      share|improve this answer

























        1












        1








        1







        Okay, hopefully this is what you need.



        I think you can try to split up the arrays first, instead of trying to work on a 3-dimensional array - since we know that it works on 1D.



        import pandas as pd

        imgg = [(1,2,1),(2,3,3),(4,1,2),(5,3,2),(6,2,1),(2,3,4),(5,6,2)]

        >>>imgg
        0 1 2
        0 1 2 1
        1 2 3 3
        2 4 1 2
        3 5 3 2
        4 6 2 1
        5 2 3 4
        6 5 6 2

        x = []
        y = []
        d = []

        # Split into components
        for img in imgg:
        x.append(img[0])
        y.append(img[1])
        d.append(img[2])

        # Compute rolling mean
        dm = pd.Series(d).rolling(window=3,center=True).mean()

        # Stitch them back to form your desired dataframe
        data = [k for k in zip(x,y,dm)]
        df = pd.DataFrame(data)

        >>>df
        0 1 2
        0 1 2 NaN
        1 2 3 2.000000
        2 4 1 2.333333
        3 5 3 1.666667
        4 6 2 2.333333
        5 2 3 2.333333
        6 5 6 NaN





        share|improve this answer













        Okay, hopefully this is what you need.



        I think you can try to split up the arrays first, instead of trying to work on a 3-dimensional array - since we know that it works on 1D.



        import pandas as pd

        imgg = [(1,2,1),(2,3,3),(4,1,2),(5,3,2),(6,2,1),(2,3,4),(5,6,2)]

        >>>imgg
        0 1 2
        0 1 2 1
        1 2 3 3
        2 4 1 2
        3 5 3 2
        4 6 2 1
        5 2 3 4
        6 5 6 2

        x = []
        y = []
        d = []

        # Split into components
        for img in imgg:
        x.append(img[0])
        y.append(img[1])
        d.append(img[2])

        # Compute rolling mean
        dm = pd.Series(d).rolling(window=3,center=True).mean()

        # Stitch them back to form your desired dataframe
        data = [k for k in zip(x,y,dm)]
        df = pd.DataFrame(data)

        >>>df
        0 1 2
        0 1 2 NaN
        1 2 3 2.000000
        2 4 1 2.333333
        3 5 3 1.666667
        4 6 2 2.333333
        5 2 3 2.333333
        6 5 6 NaN






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 7:29









        kerweikerwei

        1,5211 gold badge9 silver badges20 bronze badges




        1,5211 gold badge9 silver badges20 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f55349964%2fhow-to-use-pandas-rolling-mean-for-3d-input-array%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현