0
$\begingroup$

My NumPy array looks like this

  array([-5.65998629e-02, -1.21844731e-01,  2.44745120e-01,  1.73819885e-01,
         -1.99641913e-01, -9.42866057e-02, ..])]
 ['آؤ_بھگت'
  array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., ..])                       ]
 ['آؤلی'
  array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0..])                       ]

When I want to search some specific word I use the built in function

arr_index = np.where(x == 'شعلہ_مزاجی')
print(arr_index)

print(x[arr_index])

When I print it gives the index, but not the second value

How to get the second value in numpy array?

$\endgroup$
3
  • $\begingroup$ Hi Abdul, this question might be relevant for this Stack Exchange, as it is more implementation. However, happy to answer: Essentially looking at the structure, I would say: x[arr_index][1] if the second value in the numpy array refers to the one-hot encoding-looking vector. $\endgroup$
    – shepan6
    Jan 24, 2023 at 7:49
  • $\begingroup$ Thank you for the answer , I have tried it but it give me the error "IndexError: index 1 is out of bounds for axis 0 with size 1" I want to fetch the embedding matrix but I could not by calling the numpy fnctions $\endgroup$ Jan 24, 2023 at 7:55
  • $\begingroup$ When I print (x.ndim)) it gives me 2 , but when I want to print x[arr_index][1] it gives me error $\endgroup$ Jan 24, 2023 at 8:03

1 Answer 1

0
$\begingroup$

Update :

I was not getting the actual index value and it will also not print if the second value does not have any encodings.

arr_index = np.where(x == 'یے')

print(len(arr_index))

value = (arr_index[0])
print(value)

result = str(value)[1:-1]

result = int(result)

value = x[(result)][1]

print(value)

This will give the embeddings

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.