python - How to make inequality sign and equality sign into a string -
i'm trying make array of strings '<=', '>=' , '='.
code made:
del_str=np.zeros((nnodes*ndofs),dtype=str) in range(nnodes*ndofs): if dels[i]>0: del_str[i]="<=" elif dels[i]<0: del_str[i]=">=" else: del_str[i]="="
i think should work when check print these:
['=' '=' '=' '=' '=' '=' '<' '>' '<' '>' '>' '<' '>' '>' '>' '>' '>' '>' '>' '>' '>' '>' '>' '>' '>' '>' '>' '>' '=' '=' '=' '=' '<' '>']
where did go wrong?? tried these:
del_str=np.zeros((nnodes*ndofs),dtype=str) in range(nnodes*ndofs): if dels[i]>0: del_str[i]="<"+"=" elif dels[i]<0: del_str[i]=">"+"=" else: del_str[i]="="
but still doesn't work. please let me know i'm missing..
your datatype allows 1 character stored. try:
del_str = np.zeros((nnodes*ndofs), dtype='|s2')
demo:
dtype=str
:
>>> del_str = np.zeros(10, dtype=str) >>> del_str array(['', '', '', '', '', '', '', '', '', ''], dtype='|s1') >>> del_str[0] = '<=' >>> del_str array(['<', '', '', '', '', '', '', '', '', ''], dtype='|s1')
dtype='|s2'
:
>>> del_str = np.zeros(10, dtype='|s2') >>> del_str array(['', '', '', '', '', '', '', '', '', ''], dtype='|s2') >>> del_str[0] = '<=' >>> del_str array(['<=', '', '', '', '', '', '', '', '', ''], dtype='|s2')
Comments
Post a Comment