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 8905365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:22:36+00:00 2026-06-15T02:22:36+00:00

Using Python NumPy to calculate the sum of the column of a matrix: import

  • 0

Using Python NumPy to calculate the sum of the column of a matrix:

import numpy
from StringIO import StringIO

fileName = 'test2.csv'
myFile = open(fileName,'r')
print "Reading data from '%s' ..." % fileName
data = myFile.read() 
myFile.close()

data = numpy.genfromtxt(StringIO(data), delimiter=',', usecols=(0,1,2))
print "Calculating ..."

print data[:,2]
sumA1 = data[:,2].sum
print "shape =", data.shape
print "sumA1 =", str(sumA1)
print "ok"

Then contents of test2.csv:

12,13,14,17
1,2,3,4
12,13,14,17
1,2,3,4
12,13,14,17
1,2,3,4
12,13,14,17
1,2,3,4
12,13,14,17

I get this output

Reading data from 'test2.csv' ...
Calculating ...
[ 14.   3.  14.   3.  14.   3.  14.   3.  14.]
shape = (9, 3)
sumA1 = <built-in method sum of numpy.ndarray object at 0x00FD8EF8>
ok

Why can’t I get “sumA1 = 82” insted of that weird message? What am I doing wrong?

Thank you very much in advance.

  • 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-06-15T02:22:38+00:00Added an answer on June 15, 2026 at 2:22 am

    You have to make a call of the sum function. Just replace this piece of code:

    sumA1 = data[:,2].sum
    

    with this one:

    sumA1 = data[:,2].sum()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing TDMA in Python using NumPy. The tridiagonal matrix is stored in three
I am using python with numpy to read in data from a numerical model
I am using Python's multiprocessing module to process large numpy arrays in parallel. The
I created a python .py with some sort methods. I'm using numpy so that
Using Python's csv module, is it possible to read an entire, large, csv file
I am looking for a function to calculate exponential moving sum in numpy or
I am currently using Python/Numpy to deal with geographical/GPS data (loving it!), and I
I am using Numpy to store data into matrices. Coming from R background, there
I am using python 2.6 with ITK wrappers (from PythonXY 2.6.6.2). I am trying
Audio processing is pretty new for me. And currently using Python Numpy for processing

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.