As in title, I need to perform numpy.exp on a very large ndarray, let's say ar, and store the result in ar itself. Can this operation be performed in-place?
Perform numpy exp function in-place
2.3k Views Asked by aretor At
2
There are 2 best solutions below
0
kmario23
On
Mike Mueller's answer is good but please note that if your array is of type int32, int, int64 etc., it will throw a TypeError. Thus, a safe way to do this is to typecast your array to float64 or float32 etc., before doing exp like,
In [12]: b
Out[12]: array([1, 2, 3, 4, 5], dtype=int32)
In [13]: np.exp(b, b)
--------------------------------------------------------------------------
TypeError: ufunc 'exp' output (typecode 'd') could not be coerced to provided
output parameter (typecode 'i') according to the casting rule ''same_kind''
Type Casting & exp:
# in-place typecasting
In [14]: b = b.astype(np.float64, copy=False)
In [15]: b
Out[15]: array([ 1., 2., 3., 4., 5.], dtype=float64)
# modifies b in-place
In [16]: np.exp(b, b)
Out[16]: array([ 2.718, 7.389, 20.086, 54.598, 148.413], dtype=float64)
Related Questions in PYTHON-3.X
- SQLAlchemy 2 Can't add additional column when specifying __table__
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Platform Generation for a Sky Hop clone
- What's the best way to breakup a large test in pytest
- chess endgame engine in Python doesn't work perfectly
- Function to create matrix of zeros and ones, with a certain density of ones
- how to create a polars dataframe giving the colum-names from a list
- Django socketio process
- How to decode audio stream using tornado websocket?
- Getting website metadata (Excel VBA/Python)
- How to get text and other elements to display over the Video in Tkinter?
- Tkinter App - My Toplevel window is not appearing. App is stuck in mainloop
- Can I use local resources for mp4 playback?
- How to pass the value of a function of one class to a function of another with the @property decorator
- Python ModuleNotFoundError for command line tools built with setup.py
Related Questions in NUMPY
- Why numpy.vectorize calls vectorized function more times than elements in the vector?
- Producing filtered random samples which can be replicated using the same seed
- Numpy array methods are faster than numpy functions?
- When I create a series of spectrograms from a long audio file, the colour intesities vary noticably
- How do I fix a NumPy ValueError for an inhomogeneous array shape?
- How should I troubleshoot "RuntimeWarning: invalid value encountered in arccos" in NumPy?
- Unravel by multi-index/group
- Calculating IRR Using Numpy
- Integrating with an array of upper limits without sacrificing time efficiency
- Why doesn't this code work? - Backpropagation algorithm
- How to remove integers from a mixed numpy array containing sub-arrays and integers?
- How to transfer object dataframe in sklearn.ensemble methods
- Rust cannot borrow as mutable
- Why does the following code detect this matrix as a non-singular matrix?
- How to detect the exact boundary of a Sudoku using OpenCV when there are multiple external boundaries?
Related Questions in MULTIDIMENSIONAL-ARRAY
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- How to populate two dimensional array
- Dynamic Nested Multi-Dimensional Arrays in Rust
- Numpy array methods are faster than numpy functions?
- Multioutput regression using GPU
- Unexpected result when assigning and printing pointer value of two-dimensional array with its name
- Getting distances of points in 2D space in an array in Fortran using the concept of broadcasting (Python)
- Using Closing Stock Balance as Opening Stock in subsequent line item
- Data structure for a console menu in Node.js with nested options that can be navigated backwards
- Consolidate column values within each subset of a multidimensional array as comma separated values
- Short for creating an array of hashes in powershell malfunction?
- How can i find every instance of a repeating string in a list, and then concatenate it to the list element that precedes it in every instance?
- Hierarchically group 2d array data by two columns and concatenate third column values in each unique path
- Sum multiple items in 2D array based on condition (javascript)
- Matrix Multiplication in using 2D arrays
Related Questions in EXP
- Use gcc to compile multiple c files, ml (masm) to compile multiple assembly files and link with extern linker: Undefined reference to '__main'
- Does the same error guarantee of Java's Math.exp also apply to StrictMath.exp?
- Writing CORDIC routines for log2 and exp2
- raise x to y where y is negative and with decimals
- React-Native DateTimePicker in InputField
- Issue connecting Express.js API in Elastic Beanstalk to MongoDB Atlas during autoscaling
- How to implement vectorize "exp" and "log" base-2 functions using AVX-512
- EXP DATASTORE SCRIPT ROBLOX
- exp() function in Matlab yields different results that exp() in python
- Non-linear equations in Cplex
- What are the difference between 'rexp(1000, 1)' and 'replicate(1000, rexp(1,1))' in R?
- do a power-up in the theme editor in wordpress
- why i get promise rejection when picking an image with expo-image-picker?
- SSRS Expression to add two column from two dataset in single cell in tablix
- must be real number, not TensorVariable
Related Questions in NUMPY-NDARRAY
- List > numpy.ndarray using np.array(list) not working in class __init__ . Problem with numpy?
- Rust cannot borrow as mutable
- PyReadonlyArray2 to Vec<T>
- How can you get the numpy datetime64 resolution from an array using the C api?
- Efficient shift and roll in numpy without pd.Series
- Can a data race occur when multiple threads access the same Numpy array?
- Why does setting flags on an NDArray view result in allocations? Are they guaranteed to be bounded?
- Is there a range of launch velocities that would get my satellite as close to Mars as possible?
- `dtype='numeric' is not compatible with arrays of bytes/strings.Convert your data to numeric values explicitly instead.`
- Using Keras for Simple Linear regression: Model not predicting correctly
- slice elements from 3d numpy array using two 1d numpy integer arrays as column and depth indices
- Differrent behavior between numpy arrays and array scalars
- Fastest way to count the number of occurrences of a list of items from a numpy.ndarray
- Numpy - summing ndarray values based on conditional indexing
- Confusing about the shape of ndarray
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can use the optional
outargument ofexp:Output:
Here all elements of
awill be replaced by the result ofexp. The return valueresis the same asa. No new array is created