0

I was going through a solution to a problem which printed the inner and outer array. But while going the solution I was not able to understand the first line in which they took the input. I'm not able to get why they have used int there. The syntax is quite confusing to me. Here is the code:

A,B = [np.array([input().split()],int) for _ in range(2)]
print(np.inner(A,B)[0][0],np.outer(A,B),sep="\n")
1
  • int is the dtype specifiying the type of the array. It's the second argument to the np.array() constructor function. Commented May 31, 2019 at 14:45

2 Answers 2

3

The usage for numpy.array is numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)

All of the named parameters in the form "name"="something" are optional. In that example they are using numpy.array(List, dtype) where the list is the split input and dtype (which stands for data type) is int or integer.

So all [np.array([input().split()],int) does is splits user input (which is input()) into a list and tells numpy to store that as a numpy.array of Integers (rather than strings or floats)

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

Comments

0

The syntax of the first line is a list comprehensions that builds a list of numpy arrays where each array contains an int

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.