0

I have this line of codes in python:

Rad[i] = {'j': JY[:, :, 0], 'h': JY[:, :, 0] + 1j * JY[:, :,2]}

with the output of Rad[i] as:

{'j': array([[0.04816103]]), 'h': array([[0.04816103-5.16810074j]])}

so, I want to have output as :

{'j': '0.04816103', 'h': '0.04816103-5.16810074j'}

How could I do that?

thanks for all

0

3 Answers 3

3
In [24]: x=np.array([[0.04816103]])                                                                          
In [25]: x                                                                                                   
Out[25]: array([[0.04816103]])
In [26]: x.shape                                                                                             
Out[26]: (1, 1)
In [27]: x[0,0]                                                                                              
Out[27]: 0.04816103
In [28]: x[0][0]                                                                                             
Out[28]: 0.04816103
In [29]: x.squeeze()                                                                                         
Out[29]: array(0.04816103)
In [30]: _.shape                                                                                             
Out[30]: ()
In [34]: x.item()                                                                                            
Out[34]: 0.04816103
Sign up to request clarification or add additional context in comments.

Comments

0

I used as this instruction, make two parameters referee one to another as below:

Rad[i] = {'j': str(JY[:, :, 0][0][0]), 'h': str(JY[:, :, 0][0][0] + 1j * JY[:, :,2][0][0])}

Output is:

{'j': '0.04816103', 'h': '(5.21626177-5.11993971j)'}

Comments

0

because you are dealing with a 1-element array, you can extract the value of it using

JY[:,:,0].item()

anywhere you are working with an array (i.e. JY[:,:,0], JY[:,:,2]), just add .item() and the output will be what you want

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.