Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python What is the Python Implementation for This?

I have a Windows text file with the following info inside it:

25 05 38 26 53 04
07 45 50 33 19 34
55 25 21 30 09 39
26 11 30 12 13 41
32 23 44 11 50 39
45 30 07 44 55 54
21 10 35 46 48 27
52 41 05 53 11 50
40 38 17 43 10 54
45 27 29 12 39 31
24 42 38 02 18 09
13 43 28 06 53 30
45 47 29 30 53 13
38 45 28 48 47 36
25 34 18 06 07 55

How can I code them to break that info apart into six columns and put each column into their own array? (Like in the image below...) Kindly include pseudo-code please - so as to guide me at least...
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    66.7 KB · Views: 5
I believe this is what you are looking for:

import numpy as np
print("\nOriginal arrays:")
x = np.array((1,2,3))
y = np.array((1,2,3))
z = np.array((1,2,3))
print("Array-1")
print(x)
new_array = np.array([x,y,z]).T
print("\nStack 1-D arrays as columns wise:")
print(new_array)

here is the output of that code:
1612846887545.png

As far as your situation is concerned, you would need:
1) create a list of lists (for argument sake, we will call this "lists")
2) open file and read each line one by one
a) convert each line into a list, using the space as a delimiter
b) add list into temp
3) iterate through each list in lists
a) call this print(np.array(list))

here is the result of ^ and of previous code
1612847561749.png
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom