Saving hourly average text file


This Content is from Stack Overflow. Question asked by Samkelo Magwala

Please advise on how to make the script below fast using python. My 16GB PC has been attempting to run for the past four hours.

    import xarray as xr
    import numpy as np
    hour_array = np.arange(0,24,3)
    str_hour = ["".join(item) for item in hour_array.astype(str)]
    len_hour_array = len(hour_array)
    lons = ds.variables['longitude'][:]
    lats = ds.variables['latitude'][:]
    print('It will take sometime.......reading dew point datan')
    d2m = ds['d2m']# grab variable 2m dew point temperature
    C = [] # creating an empty array that will store the mean
    for day_offset in range(0,len_hour_array):
        month_number = hour_array[day_offset]
        month_name = str_hour[day_offset]
        hour_data = d2m_hour[day_offset,60:69,136:153] 


Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?