Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3666734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:54:58+00:00 2026-05-19T01:54:58+00:00

The following code: import numpy as p myarr=[[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6]] copy=p.array(myarr) p.mean(copy)[:,1] Is generating the following

  • 0

The following code:

import numpy as p
myarr=[[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6],[0,1],[0,6]]
copy=p.array(myarr)
p.mean(copy)[:,1]

Is generating the following error message:

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    p.mean(copy)[:,1]
IndexError: 0-d arrays can only use a single () or a list of newaxes (and a single ...) as an index

I looked up the syntax at this link and I seem to be using the correct syntax to slice. However, when I type

copy[:,1]

into the Python shell, it gives me the following output, which is clearly wrong, and is probably what is throwing the error:

array([1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6])

Can anyone show me how to fix my code so that I can extract the second column and then take the mean of the second column as intended in the original code above?

EDIT:

Thank you for your solutions. However, my posting was an oversimplification of my real problem. I used your solutions in my real code, and got a new error. Here is my real code with one of your solutions that I tried:

    filteredSignalArray=p.array(filteredSignalArray)

    logical=p.logical_and(EndTime-10.0<=matchingTimeArray,matchingTimeArray<=EndTime)
    finalStageTime=matchingTimeArray.compress(logical)
    finalStageFiltered=filteredSignalArray.compress(logical)

    for j in range(len(finalStageTime)):
        if j == 0:
            outputArray=[[finalStageTime[j],finalStageFiltered[j]]]
        else:
            outputArray+=[[finalStageTime[j],finalStageFiltered[j]]]

    print 'outputArray[:,1].mean() is:  ',outputArray[:,1].mean()

And here is the error message that is now being generated by the new code:

File "mypath\myscript.py", line 1545, in WriteToOutput10SecondsBeforeTimeMarker
    print 'outputArray[:,1].mean() is:  ',outputArray[:,1].mean()
TypeError: list indices must be integers, not tuple

Second EDIT:

This is solved now that I added:

    outputArray=p.array(outputArray)

above my code.

I have been at this too many hours and need to take a break for a while if I am making these kinds of mistakes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:54:59+00:00Added an answer on May 19, 2026 at 1:54 am

    You probably mean p.mean(copy[:,1]) with the indexing before the mean() function call. I don’t see the problem with the contents of copy – it looks right to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I create a plot with matplotlib using the following code: import numpy as
I am getting really weird timings for the following code: import numpy as np
Consider the following code: from numpy import log2 import matplotlib.pyplot as plt xdata =
If you try the following code segment import numpy as np import numpy.ma as
I have 3 1-D ndarrays: x, y, z and the following code: import numpy
Consider the following Python code: In [1]: import numpy as np In [2]: import
The following code is from the Numpy 1.4.1 manual, numpy.char import numpy as np
I have the following code which first selects elements of a NumPy array with
I have the following code: import numpy def numpysum(n): a = numpy.arange(n) ** 2
I have the following code import smtplib from email.mime.text import MIMEText smtpserver = 'smtp.gmail.com'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.