Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subdividing a column
#3
(Jun-28-2021, 02:25 AM)Larz60+ Wrote: what have you tried?

EDIT
For now I can only read the column of numbers from "input.txt" file and write 4 files for the 4 subdivisions:

input.txt file:
5 
77 
1
-4
9
17
13
2
1
5
63
8
#python3.6
import numpy as np   

d = np.loadtxt('input.txt')

A= 4
B= 2
C= 5
D= 1

with open('output1.txt', 'w') as f_out:
    for i in range(0,A):
        f_out.write(f"{d[i]}\n")
         
with open('output2.txt', 'w') as f_out:   
    for i in range(A,A+B):
        f_out.write(f"{d[i]}\n")

with open('output3.txt', 'w') as f_out:
    for i in range(A+B,A+B+C):
        f_out.write(f"{d[i]}\n")
         
with open('output4.txt', 'w') as f_out:   
    for i in range(A+B+C,A+B+C+D):
        f_out.write(f"{d[i]}\n")
output1.txt file:
Output:
5 77 1 -4
output2.txt file:
Output:
9 17
output3.txt file:
Output:
13 2 1 5 63
output4.txt file:
Output:
8
But I'm trying to write only one text file with 4 columns.

Bye,

m.
Reply


Messages In This Thread
Subdividing a column - by mesh01 - Jun-27-2021, 04:18 PM
RE: Subdividing a column - by Larz60+ - Jun-28-2021, 02:25 AM
RE: Subdividing a column - by mesh01 - Jun-28-2021, 10:00 PM
RE: Subdividing a column - by bowlofred - Jun-28-2021, 11:05 PM
RE: Subdividing a column - by mesh01 - Jun-29-2021, 01:35 PM
RE: Subdividing a column - by mesh01 - Jul-02-2021, 01:06 PM
RE: Subdividing a column - by deanhystad - Jul-02-2021, 04:52 PM
RE: Subdividing a column - by bowlofred - Jul-02-2021, 09:20 PM
RE: Subdividing a column - by perfringo - Jul-04-2021, 06:59 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020