Click here to Skip to main content
15,946,342 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
code:

import numpy as np
x=np.array([[1,2,3,5,6],[7,8,9,0,1],[3,7,0,7,6]])
print(x)
print(x[1:4,2:])

Output:

[[1 2 3 5 6]
[7 8 9 0 1]
[3 7 0 7 6]]

[[9 0 1]
[0 7 6]]

What I have tried:

I was just trying slicing can somebody explain the mechanism of this code
Posted

1 solution

The second print statement
Python
print(x[1:4,2:])

instructs the system to print the array entries with index 1,2 and 3, selecting elements 2, 3, 4 ... etc. So if you examine the array x[1] is [7,8,9,0,1] and entries 2 to the end are 9,0 and 1. You can see the same for x[2].
 
Share this answer
 

Add your solution here

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900