The Wayback Machine - https://web.archive.org/web/20240605011345/https://www.geeksforgeeks.org/numpy-put-python/
Open In App

numpy.put() in Python

Last Updated : 08 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The numpy.put() function replaces specific elements of an array with given values of p_array. Array indexed works on flattened array. 
 

Syntax: numpy.put(array, indices, p_array, mode = 'raise')

Parameters : 

array   : array_like, target array
indices : index of the values to be fetched
p_array : array_like, values to be placed in target array
mode    : [{‘raise’, ‘wrap’, ‘clip’}, optional] mentions how out-of-bound indices will behave
                  raise : [default]raise an error 
                  wrap  : wrap around
                  clip  : clip to the range

 

Python




# Python Program explaining
# numpy.put()
  
import numpy as geek
  
a = geek.arange(5)
geek.put(a, [0, 2], [-44, -55])
print("After put : \n", a)


Output : 

After put : 
[-44,   1, -55,   3,   4]

 

Python




# Python Program explaining
# numpy.put()
  
import numpy as geek
  
a = geek.arange(5)
geek.put(a, 22, -5, mode='clip')
print("After put : \n", a)


Output : 

array([ 0,  1,  2,  3, -5])

Note : 
These codes won’t run on online IDE’s. So please, run them on your systems to explore the working.

 


Similar Reads

Python | Numpy matrix.put()
With the help of Numpy matrix.put() method, we can put the value by passing index and value in a given matrix. Syntax : matrix.put(index, value) Return : Return new matrix Example #1 : In this example we can see that we are able to put the value from in given matrix with the help of method matrix.put(). # import the important module in python impor
1 min read
Numpy recarray.put() function | Python
In numpy, arrays may have a data-types containing fields, analogous to columns in a spreadsheet. An example is [(a, int), (b, float)], where each entry in the array is a pair of (int, float). Normally, these attributes are accessed using dictionary lookups such as arr['a'] and arr['b']. Record arrays allow the fields to be accessed as members of th
3 min read
Regex in Python to put spaces between words starting with capital letters
Given an array of characters, which is basically a sentence. However, there is no space between different words and the first letter of every word is in uppercase. You need to print this sentence after the following amendments: Put a single space between these words. Convert the uppercase letters to lowercase Examples: Input : BruceWayneIsBatmanOut
2 min read
Python | How to put limits on Memory and CPU Usage
This article aims to show how to put limits on the memory or CPU use of a program running. Well to do so, Resource module can be used and thus both the task can be performed very well as shown in the code given below: Code #1 : Restrict CPU time # importing libraries import signal import resource import os # checking time limit exceed def time_exce
2 min read
PUT method - Python requests
Requests library is one of the important aspects of Python for making HTTP requests to a specified URL. This article revolves around how one can make PUT request to a specified URL using requests.put() method. Before checking out the PUT method, let's figure out what a Http PUT request is - PUT Http Method PUT is a request method supported by HTTP
3 min read
Change your way to put logic in your code - Python
Aren't you bored coding in the same traditional logic over these years. It's time to bring some differences. Well, be it any programming language. When we are asked to do some sort of basic programming exercises like sorting, searching, prime number checking, etc. we are all driven towards the same boat, which is the same coding logic. Now, we are
5 min read
Put String in A Set in Python
Imagine you have a magical box in Python that only stores unique items – that's exactly what a set is! Sets are like special containers designed to hold a bunch of different things without any duplicates. In Python, they provide a versatile and efficient way to manage collections of distinct elements. Now, let's dive into the magic of sets and expl
3 min read
Python | Numpy numpy.resize()
With the help of Numpy numpy.resize(), we can resize the size of an array. Array can be of any shape but to resize it we just need the size i.e (2, 2), (2, 3) and many more. During resizing numpy append zeros if values at a particular place is missing. Parameters: new_shape : [tuple of ints, or n ints] Shape of resized array refcheck : [bool, optio
2 min read
Python | Numpy numpy.transpose()
With the help of Numpy numpy.transpose(), We can perform the simple function of transpose within one line by using numpy.transpose() method of Numpy. It can transpose the 2-D arrays on the other hand it has no effect on 1-D arrays. This method transpose the 2-D numpy array. Parameters: axes : [None, tuple of ints, or n ints] If anyone wants to pass
2 min read
Python | Numpy numpy.ndarray.__lt__()
With the help of numpy.ndarray.__lt__() method of Numpy, We can find that which element in an array is less than the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__lt__($self, value, /) Return: self<value Example #1 : In this example we can see that
1 min read
Practice Tags :