Skip to content
Advertisement

Setting integers inside array to a fixed length

I´m trying to generate an array with integers of a fixed length of 6, so that e.g. 1234 is displayed as 001234 and 12345 as 012345. I can get it to work for an integer using:

JavaScript

I tried the same method for an array, but it doesn`t seem to work, so how can I convert this method to array entries?

JavaScript

Do I need convert the array entries to strings first?

Advertisement

Answer

If you set:

JavaScript

it allows the numpy array to contain integers and strings simultaneously, which was your problem. With this simple dtype argument your code will work.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement