Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy indexing arrays

import numpy as np

# create numpy array
arr = np.array([1, 2, 3, 4, 5])

# first element of array
print('1st element of array arr[0]: ', arr[0])

# 2d array
arr = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
print('2nd element on 1st row: ', arr[0, 1])
Comment

indexing a numpy array in python

array = [[0  1  2  3  4  5] 
  [6 7 8 9 10 11]
  [12 13 14 15 16 17]
  [18 19 20 21 22 23]
  [24 25 26 27 28 29]
  [30 31 32 33 34 35]]
array[0, 3:5]  =  [3 4]

array[4:, 4:] = [[28 29],
             [34 35]]

array[:, 2] =  [2 8 14 20 26 32]

array[2:;2, ::2] = [[12 14 16],
                [24 26 28]]
Comment

numpy indexing

>>> x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> x[1:7:2]
array([1, 3, 5])
Comment

PREVIOUS NEXT
Code Example
Python :: convert list of lists to pandas dataframe 
Python :: django create view 
Python :: Display head of the DataFrame 
Python :: flat numpy array 
Python :: similarity index in python 
Python :: group by month and day pandas 
Python :: python dataframe save 
Python :: python enumerate unique values 
Python :: python tkinter messagebox 
Python :: compare multiple columns in pandas 
Python :: lists to dictionary python 
Python :: np.arrange 
Python :: use a csv file on internet as an api in python 
Python :: file open in python 
Python :: while loops python 
Python :: variables and data types in python 
Python :: pronic number program in python 
Python :: print list in one line python 
Python :: how to decrease size of graph in plt.scatter 
Python :: get the path of a module in python 
Python :: python for loop index 
Python :: make sure it only has letters and numbers python 
Python :: how to read json from python 
Python :: <IPython.core.display.HTML object 
Python :: python for dummies 
Python :: django cleanup 
Python :: how to merge two column pandas 
Python :: python tkinter checkbox default value 
Python :: Converting objects into integers in python 
Python :: python update header row 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =