Musica = np.zeros((row*120,3))
for k in range(21, 90):
for i in range(row):
for j in range(Max[k], Min[k]):
Musica[i*120 + j,:] = 0,i,j
if np.all(data[i*col + j,:]==(255.000,0.000,0.000,i,j)):
Music[i*120 + j,:] = 1,i,j
Max[k]
and Min[k]
are number that belong to the mathematical interger group, but I get this message from python
"TypeError: range() integer end argument expected, got numpy.float64."
How do I call a np.zeros
of the integer type ?
Right now I am trying to use the fallowing code:
Musica = np.zeros((row*120,3))
for k in range(21, 90):
for i in range(row):
Max = int(Max[k])
Min = int(Min[k])
for j in range(Max, Min):
Musica[i*120 + j,:] = 0,i,j
if np.all(data[i*col + j,:]==(255.000,0.000,0.000,i,j)):
Musica[i*120 + j,:] = 1,i,j
And the error message I am receiving is:
Traceback (most recent call last):
File "<ipython-input-115-4aef2441146c>", line 1, in <module>
runfile('C:/Users/Arthur_USP/Desktop/Informação/Nova abordagem/untitled0.py', wdir='C:/Users/Arthur_USP/Desktop/Informação/Nova abordagem')
File "C:\Users\Arthur_USP\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "C:\Users\Arthur_USP\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/Arthur_USP/Desktop/Informação/Nova abordagem/untitled0.py", line 181, in <module>
TypeError: 'int' object has no attribute '__getitem__'
Where line 181 is "Max = int(Max[k])"
The syntax of the NumPy zeros function You basically call the function with the code numpy. zeros() . Then inside the zeros() function, there is a set of arguments. The first positional argument is a tuple of values that specifies the dimensions of the new array.
The numpy.zeros() function returns a new array of given shape and type, with zeros. Syntax: numpy.zeros(shape, dtype = None, order = 'C')
The zeros() function is used to get a new array of given shape and type, filled with zeros. Shape of the new array, e.g., (2, 3) or 2. The desired data-type for the array, e.g., numpy. int8.
Python Numpy – zeros(shape) To create a numpy array with zeros, given shape of the array, use numpy. zeros() function. shape could be an int for 1D array and tuple of ints for N-D array.
You could try np.zeros(shape).astype(int)
.
EDIT:
Actually, zeros accepts the dtype argument. So even better is np.zeros(shape, dtype=int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With