1

simple numpy array with repeats won't sort ? need AA AA AA AA AAPL AAPL AAPL etc.

this is the code

print('pre sort',my_symbols)
np.sort(my_symbols)
print('post sort',my_symbols)

which gives the output

pre sort ['AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' 'BAC' 'BBY' 'BIDU' 'BMY' 'BTU' C' 'CAT' 'YUM' 'AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' 'BAC' 'BBY' 'BIDU' 'BMY'  'BTU' 'C' 'CAT' 'YUM' 'AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' 'BAC' 'BBY' 'BIDU' 'BMY' 'BTU' 'C' 'CAT' 'YUM' 'AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' BAC' 'BBY' 'BIDU' 'BMY' 'BTU' 'C' 'CAT' 'YUM']



post sort ['AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' 'BAC' 'BBY' 'BIDU' 'BMY' 'BTU' 'C' 'CAT' 'YUM' 'AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' 'BAC' 'BBY' 'BIDU' 'BMY' 'BTU' 'C' 'CAT' 'YUM' 'AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' 'BAC' 'BBY' 'BIDU' 'BMY' 'BTU' 'C' 'CAT' 'YUM' 'AA' 'AAPL' 'AIG' 'AMZN' 'APOL' 'BA' 'BAC' 'BBY' 'BIDU' 'BMY' 'BTU' 'C' 'CAT' 'YUM']

what am I doing wrong please

1 Answer 1

3

The np.sort function is not in place, it returns an array. To sort in place you must use the array.sort method : my_symbols.sort().

Sign up to request clarification or add additional context in comments.

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.