Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

why numpy.ndarray is object is not callable in my simple for python loop

Asked by Ajit Yadav Apr 8, 2021 752 views 1 answer
Share

About this question

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

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:
data=np.loadtxt(fname="textfile.txt")
## to load the above two column 
xy= data for XY in xy: 
i=0 
Z=XY(i,0)+XY(i,1) 
i=i+1 
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.

[ 
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:

data=np.loadtxt(fname="textfile.txt")
## to load the above two column 
xy= data for XY in xy: 
i=0 
Z=XY(i,0)+XY(i,1) 
i=i+1 
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.

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.