0

I have a method where it checks if we are at row 0.

If yes: it creates the Numpy array as that row. If no: it appends the row to the Numpy array

def printStatement(row):  
    global newData
    if(count == 0):
        newData = np.array(row)

    else:
        print("Made it to second row")
        np.append(newData, row) 

It does confirm that it made it to the else statement. But newData does not grow past the first row.

Is there something I need to specify when creating the array? All rows are the same shape.

***2D Array (Added for search engine)

2
  • 1
    Have you tried np.array([row, row, row,...])? Commented Mar 29, 2021 at 5:58
  • There are 23k+ rows. Commented Mar 29, 2021 at 12:59

1 Answer 1

1

You're not storing the result, assign it to something. E.g. newData = no.append(newData, row)

Quoting https://numpy.org/doc/stable/reference/generated/numpy.append.html:

A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled.

And by the way, prefer avoiding np.append unless really necessary.

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

4 Comments

What do i use instead?
prefer a list, convert to an array once
I'm trying to understand what you mean. Can you elaborate?
All I'm saying is collect the rows in a list, then convert to array in one go.

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.