How to add integer to python array?

0 votes

I am trying to add an integer to an already existing array. But I am getting the following error:

 "AttributeError: 'numpy.ndarray' object has no attribute 'append'"

This is the code I am using:

import numpy as np

data = np.array(f['abc']['efg']['xyz'])
data.append(0)
Feb 3 in Python by Kishan
171 views

1 answer to this question.

0 votes

You have defined a numpy array but you are trying to append data using normal python method which is not applicable on numpy arrays. Try using numpy append method: 

data = np.append(data, 0)
answered Feb 3 by Omkar
• 67,380 points

Related Questions In Python

+4 votes
7 answers
+2 votes
11 answers
0 votes
1 answer
0 votes
1 answer

How to add a new line in Python?

You can use '\n' for a next ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
88 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 220 views
+4 votes
6 answers
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 67,380 points

edited Aug 8, 2018 by Omkar 633 views
+1 vote
1 answer

How to append an integer to a string?

You can not directly concatenate two different ...READ MORE

answered Aug 16, 2018 in Python by Omkar
• 67,380 points
53 views