View onto a numpy array?

+1 vote

View Onto A NumPy Array
I have a 2D numpy array. Is there a way to create a view onto it that would include the first k rows and all columns?

Apr 15, 2018 in Python by ana1504.k
• 7,870 points
56 views

2 answers to this question.

0 votes

It;s really easy, just specify the index value, for example:
x-> NumPy Array, K-> Rows that you want.
x[:k, :]

answered Apr 15, 2018 by anto.trigg4
• 3,420 points
+1 vote

 just index it as you normally would. E.g. y = x[:k, :] This will return a view into the original array. No data will be copied, and any updates made to y will be reflected in x and vice versa.

answered Oct 18, 2018 by roberto

Related Questions In Python

0 votes
1 answer

Is an array a view of another?

The array has a base attribute, as ...READ MORE

answered Apr 23 in Python by SDeb
• 13,180 points
29 views
0 votes
1 answer

How do I turn a list into numpy array?

Use this line: numpy_array = np.array(list) And printing/displaying the ...READ MORE

answered May 24 in Python by Isha
45 views
0 votes
1 answer

Error while converting a list into a numpy array

The only possible reason I could think ...READ MORE

answered Jun 13 in Python by Rhea
47 views
0 votes
1 answer
0 votes
1 answer

How can I define a multidimensional array in python using ctype?

Here's one quick-and-dirty method: >>> A = ((ctypes.c_float ...READ MORE

answered Oct 9, 2018 in Python by ariaholic
• 7,340 points
408 views
0 votes
1 answer

How to save Numpy array as image in python?

If you have matplotlib, you can do: import ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,520 points
2,411 views
0 votes
1 answer

Printing a large numpy array

numpy.set_printoptions(threshold='nan') READ MORE

answered Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
125 views