Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call A np.zeros of integers?

Tags:

python

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])"

like image 562
NeedHelp Avatar asked Jul 12 '16 01:07

NeedHelp


People also ask

How do you call NP zeros?

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.

What is the meaning of NP zeros?

The numpy.zeros() function returns a new array of given shape and type, with zeros. Syntax: numpy.zeros(shape, dtype = None, order = 'C')

How do you make a NumPy array of all zeros?

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.

How do you declare zeros in Python?

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.


Video Answer


1 Answers

You could try np.zeros(shape).astype(int).

EDIT: Actually, zeros accepts the dtype argument. So even better is np.zeros(shape, dtype=int)

like image 194
Gilly Avatar answered Oct 24 '22 11:10

Gilly