All Questions
52 questions
0
votes
2
answers
618
views
Using scipy.optimize library to find minimum of a function
initially I write this code through many iterations and it works fine.
import numpy as np
from scipy.optimize import minimize
# Define the sigmoid function
def sigmoid(x):
return 1 / (1 + np.exp(-...
0
votes
2
answers
128
views
Is it possible to flatten an array with two different major orders without using for loop?
In python, I would like to flatten an array that are 3 dimensional. Say shape (10, 15, 200). But the first two would need to be flattened with row-major order while the remaining flatten operation ...
0
votes
1
answer
114
views
Get the first column of 3D numpy array
I have two numpys arrays:
true_values = (464, 1, 1)
pred_values = (464, 1, 4))
I want only to extract the first diminstion values (464) from the both arrays as I want to compare the rows of the first ...
0
votes
0
answers
104
views
Why is this code using both flatten() and reshape(1,-1)?
I have two questions:
Why has the programmer used both reshape(1, -1) and flatten? I think they do the same thing (convert rows to columns).
Is the role of axis=0 to add the remaining n-20 rows ...
0
votes
2
answers
422
views
Can't transform 2D array to 1D in numpy
So I wanto to multiply a vector (1D array) by a rotation matrix (2D array) but the resulted vector turns out 2D. flatten or ravel for some reason still return a 2D array.
import numpy as np
a = np....
0
votes
1
answer
92
views
(Pandas Dataframe) How do I permute or combine rows and columns to a new attribute?
for example, I have a table like this:
a b
e 20 30
d 60 50
f 120 10
my desired result is:
a_e a_d a_f b_e b_d b_f
1 20 60 120 30 50 10
I tried redo the crosstab and pivot ...
1
vote
2
answers
267
views
Why doesn't numpy flatten() work after converting a nested list into an array?
I created a nested list and converted both the inner lists and the whole list into a numpy array, but numpy flatten() failed to flatten the final array.
a = [1]
b = [2, 3]
c = [4, 5, 6]
d = [7, 8]
e = ...
0
votes
1
answer
451
views
Get a flat view of a numpy array or an exception
This question and its answers ...
reshape((-1,)) gets a view whenever the strides of the array allow it even if that means you don't always get a contiguous array.
... raised another question: ...
0
votes
0
answers
329
views
How can the euclidean distance be calculated from csv
I have a CSV file and a target vector. My aim is to calculate Euclidean distance with each row points from the target vector but I'm unable to perform this action because different errors have been ...
0
votes
1
answer
181
views
python numpy array reduction distance between elements [duplicate]
I have an array in python made like this:
array([ 18, 36, 54, ..., 9893804, 9893822, 9893840],
dtype=int64)
I wish to obtain an array containing the "distances" bewteen ...
1
vote
1
answer
122
views
convert or flatten an ndarray of arbitrary shape to a 1D array [duplicate]
what is the method to convert an array of arbitrary shape to a 1D array in python? I'm looking for something like this
my_array = numpy.array( [4,[5,6],[7,8,9]] )
my_array_flattened = [4,5,6,7,8,9]
...
-1
votes
4
answers
418
views
Flatten all subarrays in an array
I got a numpy array X which have shape (2 , 2 , 3) like this:
X = [[[1 , 2 , 3 ]
[4 , 5 , 6]] ,
[[7 , 8 , 9 ]
[10, 11, 12 ]],
I want to flatten all subarrays and turn X ...
2
votes
4
answers
330
views
Flatten inner tuples inside 3D NumPy array and save to CSV as floats
I would like to flatten the innermost and outermost axes of a 3(/4) dimensional NumPy array, when the innermost rows contain mixed-type entries: both floats and arrays/tuples of floats. I would then ...
1
vote
1
answer
267
views
Flatten and merge arrays and then split them back
Suppose that I have 3 matrces w2,w3 and w4 with shapes (5,5) (5,5) and (5,1)
Is there any efficient way to create a flatten array of those 3 matrices with shape (55,1) or (55,) (do some calculations) ...
0
votes
1
answer
43
views
Comparing two same-shape Numpy arrays, one against a set of conditions to then change the other one
array_one and array_two can be assumed to be the same shape.
I want to test array_two against two conditions (that it's not "invalid_data" and the value is one of the numbers in "...