Skip to content

Instantly share code, notes, and snippets.

@pwberrett
Created September 27, 2021 15:16
Show Gist options
  • Save pwberrett/9ef75ab8a4178db950f0d79e81510ce8 to your computer and use it in GitHub Desktop.
Save pwberrett/9ef75ab8a4178db950f0d79e81510ce8 to your computer and use it in GitHub Desktop.
problem
first set of code
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 27 14:16:09 2021
@author: pberr
"""
import numpy as np
def quickisin(example,file2new):
file2new=set(file2new)
print("example = ",type(example))
print("example shape = ",example.shape)
print("file2new = ",type(file2new))
print("file2newlength = ",len(file2new))
p=[]
t=len(example)
for j in range (0,t):
h=example[j]
k=set(h)
s1 = [item in file2new for item in k]
p.append(s1)
q=np.asarray(p)
print("final shape is ",q.shape)
return q
file2new=set([1.2,2.2,3.2,10.1,50.2,60.5,70.8,100.1])
example=[[ 10.1,20.1,30.1,40.1,50.1,60.1,70.1,80.1,90.1,100.1],[10.1,20.1,30.1,40.1,50.1,60.1,70.1,80.1,90.1,100.1] ]
example=np.asarray(example)
r=quickisin(example,file2new)
print(r.shape)
print(r)
result is
runcell(0, 'C:/A/untitled8.py')
example = <class 'numpy.ndarray'>
example shape = (2, 10)
file2new = <class 'set'>
file2newlength = 8
final shape is (2, 10)
(2, 10)
[[ True False False True False False False False False False]
[ True False False True False False False False False False]]
when I use the above subrotine in my larger program i.e
def quickisin(example,file2new):
file2new=set(file2new)
print("example = ",type(example))
print("example shape = ",example.shape)
print("file2new = ",type(file2new))
print("file2newlength = ",len(file2new))
p=[]
t=len(example)
for j in range (0,t):
h=example[j]
k=set(h)
s1 = [item in file2new for item in k]
p.append(s1)
q=np.asarray(p)
print("final shape is ",q.shape)
return q
and feed it a larger exampel and file2new this is what happens
example = <class 'numpy.ndarray'>
example shape = (702, 585)
file2new = <class 'set'>
file2newlength = 687
final shape is (702,)
The final shape should be (702,585). Why is this happening? Its the same subroutine,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment