[Numpy-discussion] how to build a series of arrays as I go?

Charles Doutriaux doutriaux1 at llnl.gov
Mon Mar 17 12:47:40 EDT 2008


Hi Chris,

1-)You could use the concatenate function to grow an array as you go.

2-) assumnig you still have your list

b=numpy.array(data[name])
bmasked=numpy.ma.masked_equal(b,-1)


Chris Withers wrote:
> Hi All,
>
> I'm using xlrd to read an excel workbook containing several columns of 
> data as follows:
>
> for r in range(1,sheet.nrows):
>      date = \
> datetime(*xlrd.xldate_as_tuple(sheet.cell_value(r,0),book.datemode))
>      if date_cut_off and date < date_cut_off:
>          continue
>      for c in range(len(names)):
>          name = names[c]
>          cell = sheet.cell(r,c)
>          if cell.ctype==xlrd.XL_CELL_EMPTY:
>              value = -1
>          elif cell.ctype==xlrd.XL_CELL_DATE:
>              value = \
> datetime(*xlrd.xldate_as_tuple(cell.value,book.datemode))
>          else:
>              value = cell.value
>          data[name].append(value)
>
> Two questions:
>
> How can I build arrays as I go instead of lists?
> (ie: the last line of the above snippet)
>
> Once I've built arrays, how can I mask the empty cells?
> (the above shows my hack-so-far of turning empty cells into -1 so I can 
> use masked_where, but it would be greato build a masked array as I went, 
> for efficiencies sake)
>
> cheers for any help!
>
> Chris
>
> PS: Slightly pissed off at actually paying for the book only to be told 
> it'll be 2 days before I can even read the online version, especially 
> given the woefully inadequate state of the currently available free 
> documentation :-(
>
>   



More information about the NumPy-Discussion mailing list