python - Separate odd and even numbers into different output files -


i'm trying separate odd , numbers 1 input file , output 2 different files (one odd numbers , other numbers).

i have never done that. how go this? have run twice have different output files?

this how it:

import numpy np  = np.loadtxt("test.txt")  odd = [] = []  ele in a:     if ele % 2 == 0:         even.append(ele)     else:         odd.append(ele) 

first read file using a = np.loadtxt("test.txt"), sort contents 2 arrays even , odd , finaly save files using np.savetxt("odd.txt", odd) , np.savetxt("even.txt", even)

edit: suggested jonrsharpe more efficiently follows:

import numpy np  = np.loadtxt("test.txt")  np.savetxt("odd.txt", a[a%2==1]) np.savetxt("even.txt", a[a%2==0]) 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -