Преобразование числового списка Python в массив чисел с плавающей запятойPython

Программы на Python
Ответить
Anonymous
 Преобразование числового списка Python в массив чисел с плавающей запятой

Сообщение Anonymous »

У меня есть список чисел, которые необходимо преобразовать в числа с плавающей запятой в массиве 45 x 45.

gauss_matrix =
  • mat_template = np.zeros([45, 45])
    for rows in np.arange(45):
    for columns in np.arange(45):
    mat_template[rows, columns] = float(gauss_matrix[np.arange(2025)])


    Это начинается со строки 0, проходит по столбцам 0–44. Затем начните со строки 2, пройдите по столбцам 0–44 и так далее?

    Решенный код: (спасибо за помощь!)
    with open('gaussfilter.csv', 'r+') as gauss: # Let's me read and write gaussfilter.csv

    GaussFilterData = gauss.readlines() # Reads the lines of the csv file
    # print("GaussFilterData: \n", GaussFilterData)

    GaussList = [] # Empty list which will be used to append values to from the csv file
    # print("GaussList 1: \n", GaussMatrix)

    for lines in GaussFilterData: # Loops through each row of data in gaussfilter.csv
    # print("lines: \n", lines)
    for row in np.arange(45): # Looping through each row and splitting up the list by commas, while converting each value to a float and not a string
    GaussList.append(float(lines.split(',')[row])) # Appending each row to GaussList

    # print("\nGaussList 2: \n", GaussList)

    # Making the array of values from GaussList
    gauss = np.zeros([45, 45]) # Matrix of zeros, the zeros are placeholders for the values in GaussList
    # print("gauss: \n", gauss)

    Counter = -1 # Counter has to start at -1 so that it begins at 0 when referring to row 0 and column 0
    for rows in np.arange(45): # Loop through rows 0 - 44
    for columns in np.arange(45): # As we are looping through row 0, loop through all 45 columns
    Counter = Counter + 1 # Counter keeps track of the number of cells in the matrix (2025)
    gauss[rows][columns] = GaussList[Counter]

    print("gauss array: \n", gauss)


    Подробнее здесь: https://stackoverflow.com/questions/498 ... y-of-float
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»