1

for some reason I can't append data to a numpy string.

for b in range(len(aUnique)):
    temp = aUnique[b]
    print(temp)
    numpy.append(sGewiss, temp)
    #RawData.cell(row=b+1, column=1).value = temp

print(sGewiss)

When I print "temp" I can see the right values so the loop is working correctly but when I print the array "sGewiss" I cannot see the new values added but only the old [66830 72312 72812].

Am I using the parameters wrong? Is there a dimension issue I am not aware of?

Thank you

I tried to add around 100 numbers to my array "sGweiss" which contains only 3 values. I was expecting an array containing the starting 3 elements plus the new 100 elements

2
  • 1
    the NumPy append method does not work "in-place" on the array that you pass it, i.e., it will not change sGewiss but will instead return a new array that is sGewiss appended with temp. You therefore have to store the return value, e.g., sGewiss = np.append(sGewiss, temp). Commented Dec 14, 2022 at 9:49
  • 1
    this kind of iterative appending is ok with list, but not with arrays. The 'numpy string' in the subject line does not make sense. Commented Dec 14, 2022 at 15:44

1 Answer 1

1

you should use :

    sGewiss = numpy.append(sGewiss, temp)

This is because NumPy append function creates a new NumPy array and returns the desired output. It does not change the input array in place.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thank you for your answer. sGewiss is a numpy list. If i use "sGewiss.append(temp)" i get an attribute error. AttributeError: 'numpy.ndarray' object has no attribute 'append'
I updated my answer. that should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.