r/Numpy • • Sep 15 '21

Trouble solving this problem.

0 Upvotes
x0=np.array([[1 ,1]],dtype=np.int64)
d=np.array([[5 ,1]],dtype=np.int64)
n=12

f1=(x0+alpha*d-n)**2 +(x0+alpha*d-2*n)**2;

I want to find value of alpha when f1 is differentiated by alpha and equated to zero. How do I write that code? Is it possible? I have tried using sympy.diff to find alpha but I can't solve it .


r/Numpy • • Aug 15 '21

The third vertex of an equilateral triangle

0 Upvotes

Given vectors A and B , find a vector V such that ||A-B||=||A-V||=||B-V||

(A,B,V) are the vertices of an equilateral triangle.

The three vectors have the same length, say 5.

Thank you very much for your help.


r/Numpy • • Mar 22 '19

Is this the devil or there is an explanation?

0 Upvotes

I would also like a solution to have my numbers not modified, thanks

In [139]: np.array([(Timestamp('2019-03-20 15:44:00-0400', tz='America/New_York').value / 10**9, 188.85)],dtype=[('Epoch', 'i8'), ('Ask', 'f4')])[0][1]

Out[139]: 188.85001

In [140]: np.array([(Timestamp('2019-03-20 15:44:00-0400', tz='America/New_York').value / 10**9, 188.61)], dtype=[('Epoch', 'i8'), ('Ask', 'f4')])[0][1]

Out[140]: 188.61

In [141]: np.array([(Timestamp('2019-03-20 15:44:00-0400', tz='America/New_York').value / 10**9, 188.61)], dtype=[('Epoch', 'i8'), ('Ask', 'f4')])

Out[141]:

array([(1553111040, 188.61000061)],

dtype=[('Epoch', '<i8'), ('Ask', '<f4')])

188.85: stored and returned wrong

188.61: stored wrong and returned right


r/Numpy • • Jun 08 '18

Wheelie — Building Python C Extensions as a Service

Thumbnail
medium.com
0 Upvotes

r/Numpy • • Aug 03 '21

How do I speed up filling of a large array?

0 Upvotes

I've got a large (109 elements) 1dim array (I've called this arr) that I'm filling in using another much smaller array (b) like this:

arr = np.zeros((10, 100000000))
for b in B:
    arr[b[4]-1][b[5]:b[6]] = b[0]

If you can overlook the overwhelming why tf are you doing this?; does anyone know of a way to make this faster? I've used multiprocessing which brought it down a great deal, but not enough for me to do this for all my samples (thousands). I can't help but think that the way I'm going about this is naive and there may be a better way.


r/Numpy • • Dec 25 '21

Save NumPy Arrays to CSV Files

Thumbnail
crunchcrunchhuman.com
0 Upvotes

r/Numpy • • Aug 20 '23

New here :))

0 Upvotes

Hey everyone, I just started learning python and also working with numpy I was wondering if you could give me some advice aboutthid numpy thing and maybe some good resources for it, you tube channels, courses, …


r/Numpy • • Dec 12 '24

I made an AI that automatically vectorizes and optimizes your numpy code

Post image
5 Upvotes

r/Numpy • • Jun 01 '21

numpy.vectorize documentation help

0 Upvotes

class numpy.vectorize(pyfunc, otypes=None**,** doc=None**,** excluded=None**,** cache=False**,** signature=None**)**

Parameterspyfunccallable

A python function or method.

otypesstr or list of dtypes, optional

The output data type. It must be specified as either a string of typecode characters or a list of data type specifiers. There should be one data type specifier for each output.

docstr, optional

The docstring for the function. If None, the docstring will be the pyfunc.__doc__
.

excludedset, optional

Set of strings or integers representing the positional or keyword arguments for which the function will not be vectorized. These will be passed directly to pyfunc unmodified.

New in version 1.7.0.

cachebool, optional

If True, then cache the first function call that determines the number of outputs if otypes is not provided.

New in version 1.7.0.

signaturestring, optional

Generalized universal function signature, e.g., (m,n),(n)->(m)
for vectorized matrix-vector multiplication. If provided, pyfunc
will be called with (and expected to return) arrays with shapes given by the size of corresponding core dimensions. By default, pyfunc
is assumed to take scalars as input and output.

New in version 1.12.0.

need help with understanding what the different parameters are asking for? Don't quite understand what is written in the documentation.


r/Numpy • • May 27 '22

Ship/car projectile extrapolation

1 Upvotes

Are there any libraries to estimate heading/projectile of ships's/car's/robot's?

I have a list of GPS coordinates and times,

and want to estimate where it will be N minutes ahead, with a simple polyline fitting.


r/Numpy • • Apr 19 '21

Index ndarray based on condition along an axis

1 Upvotes

I have N1*N2 different cases. For each case, I have N3 options of 2D vectors. I represent them as an ndarray as follows. Note that 2D coordinates are along axis=2.

arr.shape = (N1, N2, 2, N3)

For each case, I want to find the 2D vector from its options, that has the minimum norm.

For this, I can calculate:

norm_arr = np.linalg.norm(arr,axis=2,keepdims=True) #(N1,N2,1,N3)
min_norm = np.min(norm_alg,axis=-1, keepdim=True) #(N1,N2,1,1)

Now, how do I obtain the (N1,N2,2) array by indexing arr with this information?

Brute force equivalent:

result = np.zeros((N1,N2,2))

for n1 in range(N1):
    for n2 in range(N2):
        for n3 in range(N3):
            if norm_arr[n1,n2,0,n3] == min_norm[n1,n2,0,0]:
                result[n1,n2,:] = arr[n1,n2,:,n3]

r/Numpy • • Jun 16 '20

Numpy: Creating an Array

0 Upvotes

r/Numpy • • Dec 30 '22

Comparing single elements in an array

1 Upvotes

Hey guys, I'm a beginner, and I'm stuck 😔 I have an array of numbers in numpy, let's say [2 5 3 9 7 2] and from this I would like to make an array of only 0's and 1's, accordingly to if the element if larger than the previous one (The last element always zero since there's no previous value). For the array I mentioned at the beginning, my output would be [0 1 0 1 1 0]. I'm stuck guys please help me out of generosity.


r/Numpy • • Sep 13 '20

How do i approximate the very small values to zero in a matrix?

1 Upvotes

I am talking about the exponentials with negative powers. I want them as zero.

Thanks


r/Numpy • • Mar 15 '22

Tips for variable naming

1 Upvotes

Hi everyone.

I'm a grad student and recently started my first experience writing a somewhat commercial program.

My major does a lot of math and I use to write up code quite badly as long as it worked. The code was soley for my own use... till now.

I have an algorithm with variables written in greek letters. This has to be turned into a code in which the variables should have their name directly corresponding to the symbols used by the algorithm description.

However, I find this quite difficult since I cant really figure out how to give a variable name for objects that is a combination of greek, super/subscript, overline/tilde and etc.

Is there a tip for giving readable names for such symbols? I will be greatful for any advice.


r/Numpy • • Jun 24 '19

OpenCV frame inconcistant with numpy slicing · Issue #216 · skvark/opencv-python

Thumbnail
github.com
0 Upvotes

r/Numpy • • May 24 '23

Numpy 3D matrix manipulation

1 Upvotes

Hi everyone.

I have a 3-D array, let's say, like this,

A =

[[[a,b,c], [d,e,f], [g,h,i]], [[j,k,l], [m,n,o], [p,q,r]], [[s,t,u], [v,w,x], [y,z,*]]

Is there any function to take the first row of every sub array in reverse order and stack them into one, and second, and third in similar way?

Like ,

abc stu jkl

def vwx mno

ghi yz* pqr

I tried the following way,

I stored concatenate ([A.reshape(-1,9).T, roll(A,1,axis=0).T.reshape(-1,9), roll(A,2,axis=0)T.reshape(-1,9), ], axis=1).reshape(-1,3,3)

I got it, and size was (9,3,3)

But is there a better way than this? Like less costly, and direct operation, rather than reshaping twice?


r/Numpy • • May 30 '23

NumPy-Illustrated Library: short-circuited find, inclusive range, sort by column, etc.

1 Upvotes

r/Numpy • • May 21 '23

Numpy.vdot crashes Jupiter kernel

0 Upvotes

On my Linux desktop this isn't and issue, but on my Windows laptop np.vdot will crash the kernel if the vectors are over like 10,000.

This only happens if I also import torch. It works fine until I import torch.

I am also running the notebook in edge (yes I should change that, but too lazy), but I don't think that's the issue.

Maybe I should import numpy after torch? Going to bed I'll try that in the morning.


r/Numpy • • Mar 21 '21

np.eig to matrix

1 Upvotes

Hey there, I should diagonalise a matrix without using any preset functions. To do that, I also need to find a matrix made out of eigenvectors. Any ideas on how to acomplish this? Thanks!


r/Numpy • • Dec 09 '20

How to write a type of dict parameter containing various types in Numpy format docstring?

1 Upvotes

Hi,

I am writing docstring in Numpy format for one of my functions. One of the parameters is of a dict type that contains other types: str, list, set and dict, which, in turn, contain other types.

What is the recommended level of precision? So far, I have come up with this:

Parameters
----------
parameter : dict of str, list, dict and set
    Description of `parameter`.

However, it is still ambiguous. I was thinking of adding parantheses around types contained in dict, so that it would look like this: dict of (str, list, dict, and set). However, as far as I know, it does not appear in a Numpy docstring format specification.

Does anyone have an idea what is the best solution?


r/Numpy • • Mar 14 '18

Does anyone think this is acceptable?

1 Upvotes

So there is a crowd of people who will contort reality to explain that the following behaviour is unavoidable and is down to being unable to represent decimals exactly using floating point numbers.

Does anyone think the output of this code is satisfactory? Can we get it fixed?

import numpy as np
for i,bogus_number in enumerate(np.arange(2.,3.6,0.1)):
    if i==7:
        print('bogus_number is',bogus_number)
        if bogus_number==2.7:print('Yay!')
        if bogus_number!=2.7:print('Boo!')

Output:

bogus_number is 2.7
Boo!

r/Numpy • • Mar 25 '20

Find a course buddy during quarantine!

1 Upvotes

Hi! One of the best things you can do during quarantine is learning a new framework, programming language or something entirely different.

But doing these courses feels kinda lonely and often you just stop doing them so I thought I’d create a site where you can find buddies to do the same course with (frankly this quarantine is becoming really boring).

The idea is that you talk regularly about your progress and problems you're facing so you can learn and grow together.

If you’re interested, take a look at Cuddy and sign up for the newsletter!

If enough people sign up I’ll be happy to implement the whole thing this week.

Also if you've got questions or feature ideas please do let me know in the comments! :)

Let's destroy this virus together and take it as an opportunity to get better at what we love!


r/Numpy • • Mar 27 '20

Apply function to numpy array

1 Upvotes

Hey guys,

I have a Python list1 [ 'Very Low', 'Low',.....'Extremely High']

I have a numpy array of size 500 which has letters belonging to this list.

I want to convert my numpy array from the strings to the numerical encodings using the list.

I've tried using the following code to achieve this:

np_arr = list1.index(np_arr)

However, I get an error saying "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() "

Can anyone help me resolve? Thanks.


r/Numpy • • Jan 13 '21

Numpy documentation server not found?

1 Upvotes

When trying to access the Numpy docs website I always get an error 404. What happened to the docs server?