I am not new at all to Python programming, but I am completely new to the Numpy module. I need to use this module for it's very fast and efficient.
Say I have an array called noise which is defined as follows:
noise = [[uniform(0, 1) for i in range(size)] for j in range(size)]
In numpy terms, it is defined, I believe, as so:
noise = np.uniform(0, 1, (size, size))
Now say I want to generate a new array which takes the noise array and replaces every element noise[i][j] of its elements by the function function(i, j)
Using python's built-in list comprehension, I would simply say:
modified_noise = [[function(i, j) for i in range(size)] for j in range(size)]
My question, is: how can I do that using the numpy module.
functiononly works with scalar inputs, right? There's no way of getting around evaluating it once for each of thesize*size(i,j) pairs, is there?modified_noiseis related tonoise.functiononly takes coordinates as arguments, notnoise.np.uniform..noise = np.random.random_sample((size, size))is the right expression. You also seem to be confused about the concept of 'replacing every element'.numpy.uniform. I used it and it actually works just as expected.modified_noiseis to be constructed fromnoise. The two are related but only inside the definition of the functionfunctionwhich in my case is a turbulance function (I called it function to give you a more abstract version of the code)