Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

I loaded a text file containing a two-column matrix (e.g. below)

1 3 

2 4 

3 5 

2 0]

My calculation is just to sum each row i.e. 1+3, 2+4, 3+5 and 2+0. I am using the below code:


## to load the above two column 

xy= data for XY in xy: 




print (Z)

But I received an error saying numpy.ndarray object is not callable. Why does this happen? How can I do this simple calculation? Thanks.

2 Answers

0 votes
by (106k points)

You are getting the error 'numpy.ndarray' the object is not callable means that you tried to call a numpy array as a function you can use the below-mentioned code in your code:-


0 votes
by (20.3k points)

You can avoid loops and do like this:

import numpy as np

data=np.loadtxt(fname="data.txt")## to load the above two column

print data

print data.sum(axis=1)

Browse Categories