Voilà mon problème , j'ai un tableau d'entier , jusque là tout va bien mais je ne sais pas comment le remplir aléatoirement avec des chiffres compris entre 2 valeurs .
Merci d'avance =D
Voilà mon problème , j'ai un tableau d'entier , jusque là tout va bien mais je ne sais pas comment le remplir aléatoirement avec des chiffres compris entre 2 valeurs .
Merci d'avance =D
Bonjour,
Qu’est ce que tu appelles un “tableau“ ?
The Basics
NumPy's main object is the homogeneous multidimensional array. This is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. Typical examples of multidimensional arrays include vectors, matrices, images and spreadsheets.
By 'multidimensional', we mean that arrays can have several dimensions or axes. Because the word dimension is ambiguous, we use axis instead. The number of axes will often be called rank.
For example, the coordinates of a point in 3D space [1, 2, 1] is an array of rank 1 ---it has one axis. That axis has a length of 3. As another example, the array
[[ 1., 0., 0.],
[ 0., 1., 2.]]
is an array of rank 2 (it is 2-dimensional). The first dimension (axis) has a length of 2, the second dimension has a length of 3. For more details see the Numpy Glossary.
The multidimensional array class is called ndarray. Note that this is not the same as the Standard Python Library class array, which is only for one-dimensional arrays.
http://www.scipy.org/Tentative_NumPy...e0d25d50f99fe2
8.6. array — Efficient arrays of numeric values
This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers. Arrays are sequence types and behave very much like lists, except that the type of objects stored in them is constrained. The type is specified at object creation time by using a type code, which is a single character. The following type codes are defined:
Type code C Type Python Type Minimum size in bytes
'c' char character 1
'b' signed char int 1
'B' unsigned char int 1
'u' Py_UNICODE Unicode character 2 (see note)
'h' signed short int 2
'H' unsigned short int 2
'i' signed int int 2
'I' unsigned int long 2
'l' signed long int 4
'L' unsigned long long 4
'f' float float 4
'd' double float 8
http://docs.python.org/library/array.html#index-217
salut,
si c'est un tableau numpy dont tu parles:
et si c'est une simple liste:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 import numpy as np a = np.random.randint(1,3,10) # retourne un tableau de 10 entiers compris entre 1 (inclus) et 3 (exclus) >>> array([2, 1, 2, 1, 1, 2, 2, 1, 2, 1])
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 import random l = [random.randint(1,2) for i in xrange(10)] # retourne une liste de 10 entiers compris entre 1 (inclus) et 2 (inclus) >>> [1, 1, 2, 1, 2, 2, 1, 2, 1, 1]
Kango a répondu comme il convient entre-temps.
Pour tout problème analogue:
http://docs.python.org/library/random.html
Ce qu'on trouve est plus important que ce qu'on cherche.
Maths de base pour les nuls (et les autres...)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 import random l = [random.randint(1,2) for i in xrange(10)] # retourne une liste de 10 entiers compris entre 1 (inclus) et 2 (inclus) >>> [1, 1, 2, 1, 2, 2, 1, 2, 1, 1]
perfect =D Merci beaucoup !!!!
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager