python - View on numpy array -


i have matrix

 m = np.zeros((5,5)) 

and have view on last row

row = m[-1] 

however if add column m:

m = np.c_[m[:,:2],[0,0,1,1,1],m[:,2:]] 

and print out row don't new column.

is there way change without use line

row = m[-1] 

again?

what want achieve here isn't possible within bounds of numpy library. see answer on numpy arrays occupying contiguous block of memory.

you can use rx library around making subject of last row.

import numpy np rx import observable, observer rx.subjects import subject  m = np.zeros((5,5))  m_stream = subject() last_row_stream = subject() last_row = none  def update_last(v):     global last_row     last_row = v  last_row_stream.subscribe(on_next=update_last) last_row_stream.on_next(m[-1])  print(last_row)  m_stream.map(     lambda v: np.insert(v, 2, [0, 0, 1, 1, 1], axis=1) ).subscribe(lambda v: last_row_stream.on_next(v[-1]))  m_stream.on_next(m)   print(last_row) 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -