2

I have a numpy array of date objects from datetime, which I have to convert into a string so I can use it as part of a SQL statement (for mysql). Generally, this works just fine:

dats = str(dates_list)
dats = string.replace(dats[1:-1],' ',"','")

except for when it's long enough that print dates_list shows the ... (ex: print numpy.arange(4000)).

I tried to directly use the repr special method (yeah, I know I shouldn't), which is supposed to provide a string representation that can be used to rebuild the object. Clearly, I can't build this array using [ 0 1 2 ..., 4997 4998 4999].

How can I get a string representation of the entire aarray?

1 Answer 1

4

Converting to a list seems to work:

dats = str(list(dates_list))

But the more correct option is to change numpy's printoptions. There is a threshold option that sets the limit to print a summary instead of the full repr. Default is 1000. You can change it to infinity:

import numpy as np
np.set_printoptions(threshold=np.inf)

dats = str(dates_list)
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.