I'm using python 3.6 .I have a numpy array let's say a.It's in this format
array(['0', '1', '2', ..., '3304686', '3304687', '3304688'],
dtype='<U7')
I have another dictionary b={1: '012', 2: '023', 3: '045',.....3304688:'01288'}
I want to retrieve each value of b and store it in another numpy array by providing the value of a as a key to b. I was planning to try in this way
z_array = np.array([])
for i in range(a.shape[0]):
z=b[i]
z_array=np.append(z_array,z)
But looking the shape of a,I'm feeling that it will be very much time consuming. Can you please suggest me some alternate approach which will be time efficient?
z_array=np.append(in a loop. That gives you quadratic time. Instead, initailizez_array = np.zeros_like(a)Then loop and assign toz_array[i] = b[i]for i in a:? And what if the keys are not available?