[Solved] python numpy arange dtpye? why converting to integer was zero

First let’s skip the complexity of a float step, and use a simple integer start and stop: In [141]: np.arange(0,5) Out[141]: array([0, 1, 2, 3, 4]) In [142]: np.arange(0,5, dtype=int) Out[142]: array([0, 1, 2, 3, 4]) In [143]: np.arange(0,5, dtype=float) Out[143]: array([0., 1., 2., 3., 4.]) In [144]: np.arange(0,5, dtype=complex) Out[144]: array([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j, … Read more

[Solved] Python Numpy Flat Function

A simple use of flat: In [410]: res = np.zeros((2,3), dtype=int) In [411]: res Out[411]: array([[0, 0, 0], [0, 0, 0]]) In [413]: res.flat[::2]=1 In [414]: res Out[414]: array([[1, 0, 1], [0, 1, 0]]) In [415]: res.ravel() Out[415]: array([1, 0, 1, 0, 1, 0]) flat is a variant on flatten and ravel. Here I use … Read more

[Solved] Python Lists and tuples

Problem is you are trying to send a array that is a python list. At first you need to convert it into nampy array. import numpy as np py_list = [439, 301, 481, 194, 208, 415, 147, 502, 333, 86, 544, 353, 229] convert_numpy = np.array(py_list ) sent = sent[np.convert_numpy,:] and for 1st line [439 … Read more

[Solved] Reshaping a weird list in python [duplicate]

IIUC, given array = [[[0,0,1,0],[0,0,0,1],[1,0,0,0],[0,1,0,0]], [[0,1,0],[1,0,0],[0,0,1],[0,0,1]], [[0],[1],[0],[1]], [[1],[1],[0],[1]]] Do import numpy as np >>> np.array(array).T array([[list([0, 0, 1, 0]), list([0, 1, 0]), list([0]), list([1])], [list([0, 0, 0, 1]), list([1, 0, 0]), list([1]), list([1])], [list([1, 0, 0, 0]), list([0, 0, 1]), list([0]), list([0])], [list([0, 1, 0, 0]), list([0, 0, 1]), list([1]), list([1])]], 2 solved Reshaping a … Read more

[Solved] applying onehotencoder on numpy array

Don’t use a new OneHotEncoder on test_data, use the first one, and only use transform() on it. Do this: test_data = onehotencoder_1.transform(test_data).toarray() Never use fit() (or fit_transform()) on testing data. The different number of columns are entirely possible because it may happen that test data dont contain some categories which are present in train data. … Read more