Python 𝘭𝘰𝘰𝘱𝘴 almost made me wait an hour. 𝘕𝘶𝘮𝘗𝘺 laughed and did it in 90 seconds. While working on an assignment, I built two versions of the same function. The first used a 𝘗𝘺𝘵𝘩𝘰𝘯 𝘭𝘰𝘰𝘱 to run 60 model evaluations one by one. The second used 𝘕𝘶𝘮𝘗𝘺 to compute all 3,600 pairwise distances in a single operation. Both gave the exact same accuracy of 50%, proving the winner's curse on a fully random dataset. But the loop version took nearly an hour to finish, while the NumPy version was done in 1 to 1.5 minutes. Why is 𝐍𝐮𝐦𝐏𝐲 so much faster? Python loops handle one task at a time and carry overhead with every single step. NumPy does the whole job at once using fast, low level C code that runs directly on your processor. So instead of comparing 60 samples one by one, NumPy compares all 60 against all 60 in one shot. When you run thousands of these operations inside a nested loop, the time savings are massive. 𝘈𝘭𝘸𝘢𝘺𝘴 𝘷𝘦𝘤𝘵𝘰𝘳𝘪𝘻𝘦 𝘺𝘰𝘶𝘳 𝘤𝘰𝘥𝘦 𝘸𝘩𝘦𝘳𝘦 𝘺𝘰𝘶 𝘤𝘢𝘯. Your future self will thank you. Read more: https://lnkd.in/dkxgWqvr #𝐌𝐚𝐜𝐡𝐢𝐧𝐞𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠 #𝐏𝐲𝐭𝐡𝐨𝐧 #𝐍𝐮𝐦𝐏𝐲 #𝐃𝐚𝐭𝐚𝐒𝐜𝐢𝐞𝐧𝐜𝐞 #𝐎𝐩𝐭𝐢𝐦𝐢𝐳𝐚𝐭𝐢𝐨𝐧 #𝐂𝐫𝐨𝐬𝐬𝐕𝐚𝐥𝐢𝐝𝐚𝐭𝐢𝐨𝐧
Nouman Bashir’s Post
More Relevant Posts
-
Scale vector search to millions without rewriting your prototype code ⚡ Building semantic search typically starts with storing vectors in Python lists and computing cosine similarity manually. But brute-force comparison scales linearly with your dataset, making every query slower as your data grows. Qdrant is a vector search engine built in Rust that indexes your vectors for fast retrieval. Key features: • In-memory mode for local prototyping with no server setup • Seamlessly scale to millions of vectors in production with the same Python API • Built-in support for cosine, dot product, and Euclidean distance • Sub-second query times even for millions of vectors ☕️ Run this code: https://bit.ly/4cCI76w #VectorDatabase #Python #SemanticSearch #DataScience
To view or add a comment, sign in
-
-
🚀 𝐃𝐚𝐲 9/60 – 60-𝐃𝐚𝐲 𝐏𝐲𝐭𝐡𝐨𝐧 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 Today's topic is "𝐂𝐨𝐧𝐝𝐢𝐭𝐢𝐨𝐧𝐚𝐥 𝐞𝐱𝐞𝐜𝐮𝐭𝐢𝐨𝐧" Conditional execution in Python using 𝒊𝒇, 𝒆𝒍𝒊𝒇 and 𝒆𝒍𝒔𝒆 enables a program to choose between alternative code paths based on boolean expressions. An if statement executes its block 𝒘𝒉𝒆𝒏 𝒕𝒉𝒆 𝒄𝒐𝒏𝒅𝒊𝒕𝒊𝒐𝒏 𝒊𝒔 𝒕𝒓𝒖𝒆; elif provides additional conditions to test 𝒊𝒇 𝒕𝒉𝒆 𝒑𝒓𝒆𝒗𝒊𝒐𝒖𝒔 𝒐𝒏𝒆𝒔 𝒂𝒓𝒆 𝒇𝒂𝒍𝒔𝒆; and else supplies a fallback block when 𝒂𝒍𝒍 𝒑𝒓𝒊𝒐𝒓 𝒄𝒐𝒏𝒅𝒊𝒕𝒊𝒐𝒏𝒔 𝒇𝒂𝒊𝒍. This structure supports clear, readable decision logic and helps handle multiple potential scenarios efficiently. 𝐄𝐱𝐚𝐦𝐩𝐥𝐞: python 𝘵𝘦𝘮𝘱𝘦𝘳𝘢𝘵𝘶𝘳𝘦 = 72 𝘪𝘧 𝘵𝘦𝘮𝘱𝘦𝘳𝘢𝘵𝘶𝘳𝘦 > 85: 𝘱𝘳𝘪𝘯𝘵("𝘐𝘵'𝘴 𝘩𝘰𝘵 𝘰𝘶𝘵𝘴𝘪𝘥𝘦.") 𝘦𝘭𝘪𝘧 𝘵𝘦𝘮𝘱𝘦𝘳𝘢𝘵𝘶𝘳𝘦 < 60: 𝘱𝘳𝘪𝘯𝘵("𝘐𝘵'𝘴 𝘤𝘩𝘪𝘭𝘭𝘺 𝘰𝘶𝘵𝘴𝘪𝘥𝘦.") 𝘦𝘭𝘴𝘦: 𝘱𝘳𝘪𝘯𝘵("𝘛𝘩𝘦 𝘵𝘦𝘮𝘱𝘦𝘳𝘢𝘵𝘶𝘳𝘦 𝘪𝘴 𝘤𝘰𝘮𝘧𝘰𝘳𝘵𝘢𝘣𝘭𝘦.") Understanding these operators made me realize how programs make decisions and perform actions based on logic. They may look like simple symbols, but they are essential for writing meaningful code. Step by step, building stronger logic. #learning #python #consistency #challenge #60days #coding #programming
To view or add a comment, sign in
-
-
𝗠𝗔𝗖𝗛𝗜𝗡𝗘 𝗟𝗘𝗔𝗥𝗡𝗜𝗡𝗚 𝗙𝗢𝗥 𝗕𝗘𝗚𝗜𝗡𝗡𝗘𝗥𝗦 𝗣𝘆𝘁𝗵𝗼𝗻 𝗘𝘀𝘀𝗲𝗻𝘁𝗶𝗮𝗹𝘀: 𝗗𝗶𝗰𝘁𝗶𝗼𝗻𝗮𝗿𝗶𝗲𝘀, 𝗗𝗮𝘁𝗮 𝗦𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲𝘀, 𝗖𝗼𝗺𝗽𝗿𝗲𝗵𝗲𝗻𝘀𝗶𝗼𝗻𝘀 & 𝗟𝗮𝗺𝗯𝗱𝗮 Good Python code is rarely about knowing more features — it’s about choosing the right tools. In this notebook, I dive into concepts that directly impact performance, clarity, and design: • How dictionaries power fast lookups • Why selecting the right data structure matters • Writing cleaner loops with list comprehensions • Simplifying logic with lambda functions #Python #PythonProgramming #LearnPython #Coding #DataStructures #SoftwareDevelopment #ProgrammingLife
To view or add a comment, sign in
-
🚀 𝐃𝐚𝐲 17/60 – 60-𝐃𝐚𝐲 𝐏𝐲𝐭𝐡𝐨𝐧 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 🦾 Today's topic is "𝐁𝐚𝐬𝐢𝐜 𝐞𝐱𝐜𝐞𝐩𝐭𝐢𝐨𝐧 𝐡𝐚𝐧𝐝𝐥𝐢𝐧𝐠" Basic exception handling in Python ensures that your program can respond gracefully to unexpected situations, such as missing files or invalid user input, without crashing. By wrapping risky operations in 𝒕𝒓𝒚-𝒆𝒙𝒄𝒆𝒑𝒕 𝒃𝒍𝒐𝒄𝒌𝒔, you separate normal logic from error handling, making code more robust and maintainable. Thoughtful exception handling includes selecting appropriate exception types, providing informative error messages, and optionally cleaning up resources or retrying operations 𝐄𝐱𝐚𝐦𝐩𝐥𝐞: 𝘵𝘳𝘺: 𝘷𝘢𝘭𝘶𝘦 = 𝘪𝘯𝘵(𝘪𝘯𝘱𝘶𝘵("𝘌𝘯𝘵𝘦𝘳 𝘢 𝘯𝘶𝘮𝘣𝘦𝘳: ")) 𝘱𝘳𝘪𝘯𝘵(𝘧"𝘠𝘰𝘶 𝘦𝘯𝘵𝘦𝘳𝘦𝘥 {𝘷𝘢𝘭𝘶𝘦}") 𝘦𝘹𝘤𝘦𝘱𝘵 𝘝𝘢𝘭𝘶𝘦𝘌𝘳𝘳𝘰𝘳: 𝘱𝘳𝘪𝘯𝘵("𝘛𝘩𝘢𝘵 𝘸𝘢𝘴 𝘯𝘰𝘵 𝘢 𝘷𝘢𝘭𝘪𝘥 𝘯𝘶𝘮𝘣𝘦𝘳. 𝘗𝘭𝘦𝘢𝘴𝘦 𝘵𝘳𝘺 𝘢𝘨𝘢𝘪𝘯.") Understanding these functions made me realize how programs make decisions and perform actions based on logic. This concept is fundamental to writing clean, bug-resistant code.Tuples and dictionaries in Python: immutable vs. mutable data structures, and practical beginner-friendly examples. A concise guide for clean, readable code. #learning #python #consistency #challenge #60days #coding #programming #exceptionhandling
To view or add a comment, sign in
-
-
Chronological isochrone maps focus on distance rather than time, created using Python and SQL, and visualized in Jupyter Notebooks for testing with various locations #isochrones https://lnkd.in/d9vDNUy2
To view or add a comment, sign in
-
🚀 Day 51 of #100DaysOfCode ✅ Solved: 1689. Partitioning Into Minimum Number of Deci-Binary Numbers Today’s problem looked tricky at first, but the solution turned out to be beautifully simple once the pattern was understood. 🔎 Problem Insight: A deci-binary number contains only digits 0 or 1. To form a number like "82734", think about each digit: If a digit is 8, we need at least 8 deci-binary numbers contributing 1 at that position. If a digit is 3, we need at least 3 deci-binary numbers at that position. 👉 So the minimum number of deci-binary numbers required is simply: 📌 The maximum digit in the given number 💡 Example: Input: "82734" Output: 8 🧠 Python Code: Python Copy code class Solution: def minPartitions(self, n: str) -> int: return int(max(n)) ⏱ Time Complexity: O(N) 💾 Space Complexity: O(1) This problem is a great example of how understanding the pattern simplifies the solution dramatically. #LeetCode #ProblemSolving #Python #DataStructures #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 30 𝐃𝐚𝐲𝐬 𝐨𝐟 𝐏𝐲𝐭𝐡𝐨𝐧 — 𝐃𝐚𝐲 #16 | 𝐋𝐢𝐬𝐭 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧𝐬 & 𝐌𝐞𝐭𝐡𝐨𝐝𝐬 Day 16 was focused on exploring list functions and methods that make working with lists more efficient and powerful. After understanding the basics of lists, I learned today that Python provides built-in methods to easily modify, manage, and analyze list data. 📌 𝐖𝐡𝐚𝐭 𝐈 𝐂𝐨𝐯𝐞𝐫𝐞𝐝: 🔹 Adding elements using 𝐚𝐩𝐩𝐞𝐧𝐝() and 𝐢𝐧𝐬𝐞𝐫𝐭() 🔹 Removing elements with 𝐫𝐞𝐦𝐨𝐯𝐞() and 𝐩𝐨𝐩() 🔹 Sorting lists using 𝐬𝐨𝐫𝐭() 🔹 Reversing lists with 𝐫𝐞𝐯𝐞𝐫𝐬𝐞() 🔹 Counting occurrences using 𝐜𝐨𝐮𝐧𝐭() 🔹 Finding element positions with 𝐢𝐧𝐝𝐞𝐱() Learning these methods made it clear how Python simplifies operations on data collections. 💡 𝐊𝐞𝐲 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Built-in list methods save time and make code cleaner by handling common operations efficiently. Day 16 complete ✅ Each new concept is making Python feel more powerful and intuitive. 💻✨ #Python #30DayChallenge #Day16 #PythonLists #ListMethods #CodingJourney #LearnToCode #Programming #TechGrowth #Consistency
To view or add a comment, sign in
-
-
🐍 Python Journey — Lab 2 Complete! After sharing my first Python lab, I'm back with Lab 2: Python Basic Data Types & Fundamental Concepts! 🎉 Here's what I explored this time: ✅ Built-in Data Types — str, int, float, bool, list, dict & more ✅ Strings — f-strings, slicing, concatenation & immutability ✅ Numbers — integers, floats, exponents & the float precision quirk (0.1 + 0.2 😅) ✅ Boolean & Truthy/Falsy values ✅ Type Conversion — int(), float(), str(), bool() ✅ Constants by convention in Python 💡 One thing that surprised me? Python strings are immutable — you can't change a character directly, you have to build a new string! Every lab is building my foundation stronger. 30 practice questions later, I feel more confident than ever. 💪 Lab 3 is coming soon — stay tuned! 🚀 #Python #Programming #CodingJourney #PythonBasics #LearningPython #UniversityOfLahore #Tech #StudentLife
To view or add a comment, sign in
-
🔍 Exploring the power of input() and eval() in python Recently, I completed a hands-on Jupyter Notebook focused on understanding Python’s input() function and the use of eval() for dynamic expression evaluation. This practical exercise helped me explore how Python interacts with users and processes real-time data efficiently. Key learnings: 1) Used the input() function to capture user inputs dynamically 2) Understood how input data is treated as strings by default 3) Applied type conversion techniques (int, float) for accurate computations 4) Explored the use of eval() to evaluate mathematical expressions directly from user input 5) Compared typecasting vs eval() for handling different input scenarios This milestone was completed under the guidance of KODI PRAKASH SENAPATI Sir, whose structured and practical approach made these concepts easy to grasp and implement. Continuing to strengthen my Python fundamentals and problem-solving skills step by step 🚀 #PythonProgramming #CodingBasics #PythonBasics #UserInput #EvalFunction
To view or add a comment, sign in
-
WOW. Just WOW. I think Marimo is a real shift in how we think about Python notebooks. Compared to Jupyter... this feels like "wait, why didn’t we have this all along?!" The killer part for me: * The notebook is just a Python or Markdown file. YES. Finally. Real Git workflows. Clean diffs. Proper code reviews. No more JSON nightmares. * Reactive execution - everything stays in sync automatically. No hidden state. No "run all and pray". * It actually feels like building a real application, not a fragile scratchpad. This is huge for data engineers and Python developers: You can finally treat notebooks like real code. Honestly, this might be the first notebook tool that I would feel comfortable putting into a serious, production-like workflow. If you're working with data, pipelines, experimentation, or even just using Python code here and there - you need to see this! Mind blown. Here is a demo of some advanced techniques. Their channel is full of other demos and intros. https://lnkd.in/dkT6c4KZ #Python #DataScience #Marimo #DataAnalysis #MachineLearning #Productivity #JupiterNotebook #DataEngineering #DataViz
17 marimo features to boost Python productivity
https://www.youtube.com/
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development