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 4, 2019 in Python by Kishan
5,142 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 4, 2019 by Omkar
• 69,210 points

Related Questions In Python

+4 votes
7 answers
+1 vote
12 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
1,018 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,070 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,491 views
+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 5, 2018 in Python by Omkar
• 69,210 points

edited Aug 8, 2018 by Omkar 7,674 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
• 69,210 points
1,242 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP