I'd like to have a numpy array that looks something like this:
X = np.array([[10, 20], [20, 25], [30, 16], [40, 18], [50, 90], [60, 87]])
I currently have dictionary values that I retrieve from firestore:
doc_ref = db.collection('CPU Logs')
query_ref = doc_ref.where(u'testData', u'==', True).order_by(u'logId')
docs = query_ref.get()
I loop through them and assign the key values to 2 variables, id and usage, before adding them to an array toAppend:
for doc in docs:
values = doc.to_dict()
id = values['logId']
usage = values['usage']
toAppend = [id, usage]
toAppend would look something like [10, 30] if the id were 10 and the usage were 30. Now, I'm having trouble trying to add it to an empty numpy array. I've tried inserting:
X = np.array([])
for doc in docs:
values = doc.to_dict()
id = values['logId']
usage = values['usage']
toAppend = [id, usage]
a = X.flatten()
np.insert(a, [0,0], toAppend)
print(X)
as well as appending:
np.append(X, toAppend)
But both don't seem to work, as the print statement just prints out [].
result = np.insert(a, [0,0], toAppend)as explained in the documentation.np.appendis a poorly named imitation, that gives many users problems.np.arrayandnp.concatenate(and thestackvariants) all take a list of arrays. Use that.