简体   繁体   中英

Convering a list into an array of dtype = int64

I have a list

y_test  = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

type(y_test)
Out[597]: list

I would like to convert this into an array of dtype int64 .

y_test
Out[598]: array([1, 1, 1, ..., 1, 0, 1], dtype=int64)

type(y_test)
Out[599]: numpy.ndarray

y_test.shape
Out[600]: (25000,)

Kindly note the shape of the result. Is this something achievable?

The function np.array can take any sequence and convert it to a numpy array. For your case, this would be

np.array(y_test)
Out: array([0, 0, 0, ..., 1, 1, 1])

You can also specify the dtype argument if you wish:

np.array(y_test, dtype=np.int64)
Out: array([0, 0, 0, ..., 1, 1, 1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM