2
array = df.as_matrix()
array = np.int(array)

I tried:

array = np.int(array)

for :

array[i][10]/5

but got :

array = np.int(array) TypeError: only length-1 arrays can be converted to Python scalars????

2
  • 1
    Use array.astype(int). Commented Sep 5, 2017 at 19:38
  • 1
    np.int is the same as the base Python int, a function that creates a (one) integer from a number or string. It does not convert an array (or list or string of multiple numbers). Commented Sep 5, 2017 at 20:26

1 Answer 1

1

Try:

>>> a = np.random.normal(20, 5, size=(2,2))
array([[ 24.04255462,  24.24954137],
       [ 14.64894245,  16.17946985]])
>>> a = a.astype(int)
>>> a
array([[24, 24],
       [14, 16]])

Check the docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.