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
21 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 65,840 points

Related Questions In Python

+4 votes
7 answers
+2 votes
11 answers

How to print array/ list without brackets in python?

name=["a","b","c"] print (', '.join(name)) It will simply take all ...READ MORE

answered Apr 18, 2018 in Python by aayushi
• 750 points
11,799 views
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
22 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
20 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
• 65,840 points

edited Aug 8, 2018 by Omkar 271 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
• 65,840 points
35 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.