Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to create a three dimensional array with standard distance one in each direction, so that i receive, with x=10; y=10; z=10; 1000 cells, for example. In the next step, i want to assign an additional variable "E" to each cell where its worth consist of a gaussian distribution with mean 1 and variance 0,1.

I have already tried to create a multidimensional array using:

import numpy as np
x = np.array([[range(11)],[range(11)],[range(11)]],dtype=int)

Aswell as:

x,y,z = mgrid[0:11, 0:11, 0:11]

But i do not know if it is the kind of type i am looking for and how to add a variable to each cell of it.

I am pretty new to programming and python. As additional modules i want to use numpy, scipy and matplotlib.

Thanks for help!

Best regards.

share|improve this question
1  
Do you want to add a random variable drawn from a Gaussian distirbution? –  doctorlove Jul 31 '13 at 9:36
    
hstack for the extra column: stackoverflow.com/questions/8486294/… –  doctorlove Jul 31 '13 at 9:38
    
Yes, i want to assign a random variable from a gaussian distributin with mean 1 and variance 0.1 for each single cell. It would follow the gaussian density function, doesn't it? –  JayandB Jul 31 '13 at 10:00

1 Answer 1

import numpy as np
E = np.random.normal(size=(1000, 1000, 1000)) * 0.1
print(E.shape)
# (1000, 1000, 1000)

print(E.var())
# 0.0100944667935

This creates a 3-dimensional array, whose elements are random variates sampled from a normal distribution (mean 0, variance 0.1).

I don't understand the first part of your question. Can you give a small concrete example of what values you want in that array?

share|improve this answer
    
Hi, thanks for this help. I want the values to be variable in size which means i want to put in a max worth for x,y and z axes. If you imagine it as a 3dimensional rubikscube with many little cubes in it, i want that every little cube has x=1 y=1 z=1 in axes lenght, so that a rubikscube with site length x=10 y=10 z=10 has 1000 of little cubes with site lenght x=1 y=1 z=1. For example "minicube" one has coordinates x=1 y=1 z=1 and minicube two has coordinates x=1 y=1 z=2, than minicube two would be next to minicube one in direction of z-axis. –  JayandB Jul 31 '13 at 10:42
    
Then is E what you are looking for? It has 1000 "little cubes" in each direction, and it is filled with random values. Remember, an array has no side length, so I don't understand how you wish to translate that aspect of your rubikscube model to a NumPy array. It would be very helpful if you can post a concrete small example of what the array should look like. –  unutbu Jul 31 '13 at 11:01
    
Hi i draw an example: s1.directupload.net/file/d/3333/gjgcxwgk_png.htm It shows the mincubes from which each should have a determined worth out of the gaussian distribution. –  JayandB Jul 31 '13 at 11:21
    
Okay, thanks for drawing. But now you have to show us what that means in terms of an array: np.array([[[...],[...],],...]). An array is not a minicube. Some attributes of a minicube, such as side length, have no analog in terms of a NumPy array. –  unutbu Jul 31 '13 at 11:48
    
Well, but i can define this minicubes by using vectors in every direction since numpy is building up the array from 0,0,0 in every direction isn't it so? In the case i would use vectors for further mathematics i could define x=1 y=1 z=1 for first and x=3, y=3, z=3 for a second point, so that numpy would automatically think i am taking the cell the vector or the vector difference is pointing to. Can python realize a 3 dimensional matrix with side length, distance between cells etc.? –  JayandB Jul 31 '13 at 13:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.