python - indexing with list comprehensions? Is it possible? -


the way i'm doing seems clunky. there better way index array?

this code works:

dem = np.empty((number_of_dem_files, demfile.shape[0], demfile.shape[1]), 'float')  t in range(number_of_dem_files):       dem[t] = np.load(dem_filename_list[t]) 

i tried doing list comprehensions this:

dem = np.load([dem_filename_list[t] t in range(number_of_dem_files)]) 

but syntax error. possible? there reason or slow i've got? there better way?

edit:

dem_filename_list looks this:

dem_filename_list = (d:/documents/data/grand_canyon_2015/03-11/dem1.npy,                      d:/documents/data/grand_canyon_2015/03-11/dem2.npy,                      d:/documents/data/grand_canyon_2015/03-11/dem3.npy,                      etc) 

the first line creates empty 3d array. ultimately, i'm trying load , store time series of arrays in 1 3d array, can index dem[t,i,j]

where t time, row number, , j column number.

this testable example, workes fine:

import numpy np  = np.array((1,2)) b = np.array((3,4))  open('12', 'wb') f:     np.save(f,a) open('34', 'wb') f:     np.save(f,b)      l = dem_filename_list  dem = [np.load(ll) ll in l]  print dem 

output:

[array([1, 2]), array([3, 4])] 

or presented annotations:

import numpy np  dem = [np.load(ll) ll in dem_filename_list]  print dem 

output:

 dem_files 

updated:

there no need row:

dem = np.empty((number_of_dem_files)) 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -