0

disclaimer: I am a beginner in python/scikit...

I loaded the iris data succesfully:

iris = datasets.load_iris()

>>>  print(iris)
{'data': array([[5.1, 3.5, 1.4, 0.2],
       [4.9, 3. , 1.4, 0.2],
       [4.7, 3.2, 1.3, 0.2],
       [4.6, 3.1, 1.5, 0.2]......

Now, for testing purposes, I want to add / append my own entry into iris['data']. So my own "flower" in this test scenario.

I found out that iris is of type Bunch, which is type of Dictionary. I tried many things, but nothing works.

What is the syntax to add an array with my own data?

Thanks for your help

Rainer
  • 103
  • 1
  • 7

1 Answers1

1

Here is an example on how to append two rows X at the end of iris['data'] and the corresponding y labels to iris['target']:

import numpy as np
from sklearn import datasets

iris = datasets.load_iris()

X = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
y = [1, 2]

iris['data'] = np.vstack([iris['data'], X])
iris['target'] = np.hstack([iris['target'], y])
Stanislas Morbieu
  • 1,721
  • 7
  • 11
  • Oh man, I tried at last an hour yesterday with no success. GREAT, this works. Did not came across that vstack/hstack bit... Thank you very much! – Rainer Nov 18 '19 at 06:23