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,890 points
92 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,440 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, 2019 in Python by SDeb
• 13,250 points
68 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, 2019 in Python by Isha
86 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, 2019 in Python by Rhea
187 views
0 votes
1 answer

How to pretty-print a numpy.array without scientific notation and with given precision?

Hii @kartik, The numpy arrays have the method round(precision) which ...READ MORE

answered Apr 14 in Python by Niroj
• 43,540 points
247 views
0 votes
1 answer

How do I read CSV data into a record array in NumPy?

Hello @kartik, You can use Numpy's genfromtxt() method to do ...READ MORE

answered Jun 22 in Python by Niroj
• 43,540 points
155 views
+1 vote
1 answer

How to convert a PIL Image into a numpy array?

Hello @kartik, You just need to convert your ...READ MORE

answered Jun 22 in Python by Niroj
• 43,540 points
126 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
294 views
0 votes
1 answer