I have an array like this numpy array
dd= [[foo 0.567 0.611]
[bar 0.469 0.479]
[noo 0.220 0.269]
[tar 0.480 0.508]
[boo 0.324 0.324]]
How would one loop through array
selecting foo and getting 0.567 0.611 as floats as a singleton.
Then select bar and getting 0.469 0.479 as floats as a singleton …..
I could get vector the first elements as list by using
dv= dd[:,1]
The ‘foo’, and ‘bar’ elements are not unknown variables, they can change.
How would I change if element is in position [1]?
[[0.567 foo2 0.611]
[0.469 bar2 0.479]
[0.220 noo2 0.269]
[0.480 tar2 0.508]
[0.324 boo2 0.324]]
You have put the NumPy tag on your Question, so i’ll assume you want NumPy syntax, which the answer before mine doesn’t use.
If in fact you wish to use NumPy, then you likely don’t want the strings in your array, otherwise you will also have to represent your floats as strings.
What you are looking for is the NumPy syntax to access elements of a 2D array by row (and exclude the first column).
That syntax is:
W/r/t the second scenario in your Question–selecting non-adjacent columns:
The small complication in your Question is just that you want to use a string for row_index, so it’s necessary to remove the strings (so you can create a 2D NumPy array of floats), replace them with numerical row indices and then create a look-up table to map the the strings with the numerical row indices:
The second scenario in your Question: what if the index column changes?