Thank you for MATLAB, but in any worst language, I want you to do the following:
I have a csv file with 1 row and 75 columns, but I want to read the values ​​into a 3 * 25 matrix.
For example, the file value is
2,4,1,3,5,1,4,5,8, ..., 3,2,9
If we have 75 values, we want to make this a 3 by 25 matrix (three in a row).

2 3 4 ... 3
4 5 5 ... 2
1 1 8 ... 9

How can I achieve this using a for statement?
There is also a powerful work to define 75 variables and put them one by one in the array, but the amount of sentences will be ridiculous, so
I want you to think of a smart way.

  • Answer # 1


    You can use any worst language

    Do not accept questions about this code.

    import numpy as np
    arr = np.loadtxt ('src.csv', delimiter = ',', dtype = np.int)
    np.savetxt (
        'dst.csv', arr.reshape (3, 25), fmt = '% d'

    In general terms, can it be realized in most languages ​​by the following method?

    src = read data (src is an array of 75 elements)
    for y in 0 ~ 3:
        for x in 0 ~ 25:
            Output y * 25 + xth element of src
            Output blank
        Output line break

    Of course there are writing methods suitable for each language, but
    If you can't come up with it, you can only write in a muddy manner.

    At least "the amount of text is outrageous".