python array output to file is'nt unicode?

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

12ten
Posts: 3
Joined: Mon Oct 15, 2012 4:52 pm UTC

python array output to file is'nt unicode?

Postby 12ten » Sat Oct 20, 2012 3:48 pm UTC

Hi,

i'm working with arrays
i've searched an array for a certain element, outputed this to a new array and write to a file

on the screen terminal the output is fine(more or less, python changes 0.00622 to 6.22e*3, be nice to change this)

but when i write to a file in gedit the result is not unicode, so i can't examine the array.

any help greatly thanked

12ten

User avatar
phlip
Restorer of Worlds
Posts: 7554
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: python array output to file is'nt unicode?

Postby phlip » Sun Oct 21, 2012 2:31 am UTC

Can you post an example of the code you're using? Also, what the output is, and what you're expecting... It's hard to guess exactly what your problem is from a vague description...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

12ten
Posts: 3
Joined: Mon Oct 15, 2012 4:52 pm UTC

Re: python array output to file is'nt unicode?

Postby 12ten » Sun Oct 21, 2012 11:58 am UTC

phlip wrote:Can you post an example of the code you're using? Also, what the output is, and what you're expecting... It's hard to guess exactly what your problem is from a vague description...


Hi, so, this is what i started of with, import an array, make a new array and try to write to an output file.

Code: Select all

import numpy as np

output = open('output.txt', 'w')
a = np.loadtxt('fs.txt')

#make a new array
b = a[a[:,2]>100,0:2]

output.write(b)
output.close()


i guess it won't work because the output must be in a string?
so i tried this

Code: Select all

g = np.array(['%.2f' % j for j in a.reshape(a.size)])


which means i can out put the data to the file, but no longer as an array
i was thinking to try to break it up after every 3 spaces and get a new line by \n, but i thing there must be a better way,

any hints?

cheers

User avatar
Mat
Posts: 414
Joined: Fri Apr 21, 2006 8:19 pm UTC
Location: London

Re: python array output to file is'nt unicode?

Postby Mat » Sun Oct 21, 2012 1:10 pm UTC

NumPy includes several functions for IO: http://docs.scipy.org/doc/numpy/referen ... es.io.html

12ten
Posts: 3
Joined: Mon Oct 15, 2012 4:52 pm UTC

Re: python array output to file is'nt unicode?

Postby 12ten » Sun Oct 21, 2012 1:42 pm UTC

Mat wrote:NumPy includes several functions for IO: http://docs.scipy.org/doc/numpy/referen ... es.io.html



thanks, that's just what i was looking for


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 13 guests