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 :: takes 2 positional arguments but 3 were given 
Python :: set empty dictionary key python 
Python :: how to get data from django session 
Python :: how to find last element in array python 
Python :: Count upper case characters in a string 
Python :: change value of column in pandas 
Python :: bitwise operation in python 
Python :: python os.walk 
Python :: Issue AttributeError: ‘numpy.ndarray’ object has no attribute ‘index’ 
Python :: django template filter 
Python :: doing math in python 
Python :: iterator in python 
Python :: raspbian run a python script at startup 
Python :: how to if in pythob 
Python :: text to speech module python 
Python :: how to make a calcukatir un python 
Python :: Convert .tif images files to .jpeg in python 
Python :: Odd number without loop in python 
Python :: round() function in python 
Python :: python for print 
Python :: Python NumPy column_stack Function Syntax 
Python :: how to unstack multiindex pandas 
Python :: sklearn euclidean distance 
Python :: detect grayscale image in python opencv 
Python :: how to block a ip adress 
Python :: shebang line python 
Python :: python << meaning 
Python :: john cabot 
Python :: emacs pipenv not working 
Python :: taggablemanager serializer django 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =