import numpy as np
A = np.array(['B'])
B = 5
C = A[0]
I would like C = 5 if that is possible.
import numpy as np
A = np.array(['B'])
B = 5
C = A[0]
I would like C = 5 if that is possible.
An approach like this sounds like it would be far better:
arr = np.array([['A', 'B', 'C'],['D', 'E', 'F'],['G', 'H', 'I']])
values = {'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'I': 9}
print(values['C'])
values['C'] = values[arr[0][1]]
print(values['C'])
Output:
3
2
You can then view the array by values by doing:
np.array(list(map(lambda row: {x:values[x] for x in row}, arr)))
Output:
array([{'A': 1, 'B': 2, 'C': 2},
{'D': 4, 'E': 5, 'F': 6},
{'G': 7, 'H': 8, 'I': 9}], dtype=object)
A = ['B']
B = {'B':5}
C = B[A[0]]
When you print C
it will give output 5
.